public function put($from, $to) { return $this->ftp->put($from, $to) && ($this->ftp->chmod($to, $this->permFile) || true); }
/** * Handles uploading processes of the migration * * @param array $files Files to upload * @param string $ftp_password FTP Password * @return bool TRUE on success, FALSE on failure */ function upload_files($files, $ftp_password) { // Load plugin settings $wpmove_options = $this->get_admin_options(); // Instantiate the FTP class $ftp = new ftp(); // Enter Passive Mode if enabled if ($wpmove_options['ftp_passive_mode']) { $ftp->Passive(TRUE); } echo '<span class="code">'; printf(__('Connecting to %s:%d...', 'WPMove'), $wpmove_options['ftp_hostname'], $wpmove_options['ftp_port']); $this->flush_output(); // Set the hostname and the port $ftp->SetServer($wpmove_options['ftp_hostname'], intval($wpmove_options['ftp_port'])); // Try connecting to the server if ($ftp->connect()) { echo ' <strong>' . __('Success!', 'WPMove') . '</strong><br>'; $this->flush_output(); // Display a different message if no password is given if ('' !== $ftp_password) { printf(__('Logging in as %s using password...', 'WPMove'), $wpmove_options['ftp_username']); } else { printf(__('Logging in as %s without a password...', 'WPMove'), $wpmove_options['ftp_username']); } $this->flush_output(); // Login to the server using the supplied credentials if ($ftp->login($wpmove_options['ftp_username'], $ftp_password)) { echo ' <strong>' . __('Success!', 'WPMove') . '</strong><br>' . __('Starting uploading files...', 'WPMove') . '<br>'; $this->flush_output(); // Changes the present working directory to the backup directory on the remote server $ftp->chdir($wpmove_options['ftp_remote_path']); // Start counting errors during the file upload $error_count = 0; // Upload the given backup files under the backup folder to the server foreach ($files as $file) { printf(__('%s is being uploaded...', 'WPMove'), basename($file)); $this->flush_output(); if (FALSE !== $ftp->put(trailingslashit(WPMOVE_BACKUP_DIR) . $file, basename($file))) { echo '<strong>' . __(' Success!', 'WPMove') . '</strong><br>'; } else { echo '<strong>' . __(' Failed!', 'WPMove') . '</strong><br>'; $error_count++; } $this->flush_output(); } // Notify the user about the errors occured if ($error_count) { printf(_n('Uploading files is completed with %d error...', 'Uploading files is completed with %d errors...', $error_count, 'WPMove'), $error_count); } else { _e('Uploading files is completed without an error...', 'WPMove'); } $this->flush_output(); echo '<br>'; _e('Closing the FTP connection...', 'WPMove'); echo '</span><br>'; // Close the connection $ftp->quit(); // Return TRUE on success return TRUE; } // Close the connection $ftp->quit(); } echo ' <strong>' . __(' Failed!', 'WPMove') . '</strong><br>' . __('Operation terminated...', 'WPMove') . '</span><br>'; // If it reaches here, apparently it failed return FALSE; }
function ftp_go() { global $list, $options, $FtpUpload, $FtpBytesTotal, $FtpChunkSize, $FtpTimeStart, $FtpUploadBytesSent, $FtpLastChunkTime, $FtpLast; require_once CLASS_DIR . "ftp.php"; $ftp = new ftp(); if (!$ftp->SetServer($_POST["host"], (int) $_POST["port"])) { $ftp->quit(); printf(lang(79), $_POST["host"] . ":" . $_POST["port"]); echo '<br /><a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />'; } else { if (!$ftp->connect()) { $ftp->quit(); echo "<br />"; printf(lang(79), $_POST["host"] . ":" . $_POST["port"]); echo '<br /><a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />'; } else { printf(lang(81), 'ftp://' . $_POST['host'] . ':' . $_POST['port']); if (!$ftp->login($_POST["login"], $_POST["password"])) { $ftp->quit(); echo "<br />"; echo lang(80); echo '<br /><a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />'; } else { //$ftp->Passive(FALSE); if (!$ftp->chdir($_POST["dir"])) { $ftp->quit(); echo "<br />"; printf(lang(159), $_POST['dir']); echo '<br /><a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />'; } else { ?> <br /> <div id="status"></div> <br /> <table cellspacing="0" cellpadding="0"> <tr> <td></td> <td> <div class="progressouter"> <div style="width:298px"> <div id="progress" class="ftpprogress"></div> </div> </div> </td> <td></td> </tr> <tr> <td align="left" id="received">0 KB</td> <td align="center" id="percent">0%</td> <td align="right" id="speed">0 KB/s</td> </tr> </table> <br /> <script type="text/javascript">switchCell(3);</script> <?php for ($i = 0; $i < count($_POST["files"]); $i++) { $file = $list[$_POST["files"][$i]]; echo '<script type="text/javascript">pr(0,0,0);changeStatus(' . "'" . addslashes(basename($file["name"])) . "', '" . $file["size"] . "');</script>"; $FtpUpload = true; $FtpBytesTotal = filesize($file['name']); $FtpChunkSize = round($FtpBytesTotal / 333); $FtpTimeStart = getmicrotime(); $FtpUploadBytesSent = $FtpLastChunkTime = $FtpLast = 0; if ($ftp->put($file["name"], basename($file["name"]))) { $time = round(getmicrotime() - $FtpTimeStart); $speed = @round($FtpBytesTotal / 1024 / $time, 2); echo '<script type="text/javascript">pr(100, ' . "'" . bytesToKbOrMbOrGb($FtpBytesTotal) . "', " . $speed . ")</script>\r\n"; flush(); if (@$_POST["del_ok"] && !$options['disable_deleting']) { if (@unlink($file["name"])) { unset($list[$_POST["files"][$i]]); } } printf(lang(160), '<a href="ftp://' . $_POST["login"] . ':' . $_POST["password"] . '@' . $_POST["host"] . ':' . $_POST["port"] . $_POST["dir"] . (substr($_POST["dir"], -1) != '/' ? '/' : '') . basename($file["name"]) . '"><b>' . basename($file["name"]) . '</b></a>'); echo "<br />" . lang(161) . ": <b>" . sec2time($time) . "</b><br />" . lang(162) . ": <b>" . $speed . " KB/s</b><br /><br />"; } else { printf(lang(163), basename($file['name'])); echo "<br />"; } } $ftp->quit(); } } } } }
/** * Generates ZIP archive * @return string|WP_Error */ protected function _generateArchive() { global $blog_id; set_time_limit(0); // Prepare archive directory $uploadDir = wp_upload_dir(); $exporter = wp_get_current_user(); $archiveName = $uploadDir['path'] . '/' . self::HOOK . '-' . $blog_id . '-' . time() . '-' . $exporter->user_login; $archiveDir = $archiveName . '/'; if (!file_exists($archiveDir)) { wp_mkdir_p($archiveDir); } // Prepare queue $baseUrl = untrailingslashit(home_url()); $newBaseUrl = untrailingslashit($this->_options->getOption('baseUrl')); $urlsQueue = array_unique(array_merge(array(trailingslashit($baseUrl)), $this->_getListOfLocalFilesByUrl(array(get_template_directory_uri())), $this->_getListOfLocalFilesByUrl(explode("\n", $this->_options->getOption('additionalUrls'))))); // Process queue $this->_exportLog = array(); while (count($urlsQueue)) { $currentUrl = array_shift($urlsQueue); //echo "Processing ". $currentUrl."<br />"; $urlResponse = new StaticHtmlOutput_UrlRequest($currentUrl); $urlResponse->cleanup(); // Add current url to the list of processed urls $this->_exportLog[$currentUrl] = true; // Add new urls to the queue foreach ($urlResponse->extractAllUrls($baseUrl) as $newUrl) { if (!isset($this->_exportLog[$newUrl]) && $newUrl != $currentUrl && !in_array($newUrl, $urlsQueue)) { //echo "Adding ".$newUrl." to the list<br />"; $urlsQueue[] = $newUrl; } } // Save url data $urlResponse->replaceBaseUlr($baseUrl, $newBaseUrl); $this->_saveUrlData($urlResponse, $archiveDir); } // Create archive object $tempZip = $archiveName . '.tmp'; $zipArchive = new ZipArchive(); if ($zipArchive->open($tempZip, ZIPARCHIVE::CREATE) !== true) { return new WP_Error('Could not create archive'); } $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($archiveDir)); foreach ($iterator as $fileName => $fileObject) { $baseName = basename($fileName); if ($baseName != '.' && $baseName != '..') { if (!$zipArchive->addFile(realpath($fileName), str_replace($archiveDir, '', $fileName))) { return new WP_Error('Could not add file: ' . $fileName); } } } $zipArchive->close(); rename($tempZip, $archiveName . '.zip'); if ($this->_options->getOption('sendViaFTP') == 1) { //crude FTP addition require_once '/home/leon/leonwp/wp-content/plugins/static-html-output-plugin/library/FTP/ftp.php'; $config = array(); //keys[passive_mode(true|false)|transfer_mode(FTP_ASCII|FTP_BINARY)|reattempts(int)|log_path|verbose(true|false)|create_mask(default:0777)] $ftp = new ftp($config); $ftp->conn($this->_options->getOption('ftpServer'), $this->_options->getOption('ftpUsername'), filter_input(INPUT_POST, 'ftpPassword')); //Crude FTP $ftp->put($this->_options->getOption('ftpRemotePath'), $archiveName . '/'); unset($ftp); } // Remove temporary files unless user requested to keep or needed for FTP transfer if ($this->_options->getOption('retainStaticFiles') != 1) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($archiveDir), RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $fileName => $fileObject) { // Remove file if ($fileObject->isDir()) { // Ignore special dirs $dirName = basename($fileName); if ($dirName != '.' && $dirName != '..') { rmdir($fileName); } } else { unlink($fileName); } } rmdir($archiveDir); } return str_replace(ABSPATH, trailingslashit(home_url()), $archiveName . '.zip'); }
function ftp_go() { global $list, $options, $L; require_once CLASS_DIR . "ftp.php"; $ftp = new ftp(); if (!$ftp->SetServer($_POST["host"], (int) $_POST["port"])) { $ftp->quit(); echo $L->sprintf($L->say['couldnt_establish_con'], $_POST["host"] . ":" . $_POST["port"]); echo '<br /><a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />'; } else { if (!$ftp->connect()) { $ftp->quit(); echo "<br />"; echo $L->sprintf($L->say['couldnt_establish_con'], $_POST["host"] . ":" . $_POST["port"]); echo '<br /><a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />'; } else { $L->sprintf($L->say['_con'], 'ftp://' . $_POST['host'] . ':' . $_POST['port']); if (!$ftp->login($_POST["login"], $_POST["password"])) { $ftp->quit(); echo "<br />"; echo $L->say['incorrect_userpass']; echo '<br /><a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />'; } else { //$ftp->Passive(FALSE); if (!$ftp->chdir($_POST["dir"])) { $ftp->quit(); echo "<br />"; echo $L->sprintf($L->say['_cant_locatefold'], $_POST['dir']); echo '<br /><a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />'; } else { ?> <br /> <div id="status"></div> <br /> <table cellspacing="0" cellpadding="0"> <tr> <td></td> <td> <div class="progressouter"> <div style="width:298px"> <div id="progress" class="ftpprogress"></div> </div> </div> </td> <td></td> </tr> <tr> <td align="left" id="received">0 KB</td> <td align="center" id="percent">0%</td> <td align="right" id="speed">0 KB/s</td> </tr> </table> <br /> <?php for ($i = 0; $i < count($_POST["files"]); $i++) { $file = $list[$_POST["files"][$i]]; echo '<script type="text/javascript">changeStatus(' . "'" . addslashes(basename($file["name"])) . "', '" . $file["size"] . "');</script>"; $FtpBytesTotal = filesize($file["name"]); $FtpTimeStart = getmicrotime(); if ($ftp->put($file["name"], basename($file["name"]))) { $time = round(getmicrotime() - $FtpTimeStart); $speed = @round($FtpBytesTotal / 1024 / $time, 2); echo '<script type="text/javascript">pr(100, ' . "'" . bytesToKbOrMbOrGb($FtpBytesTotal) . "', " . $speed . ")</script>\r\n"; flush(); if ($_POST["del_ok"] && !$options['disable_to']['act_del']) { if (@unlink($file["name"])) { unset($list[$_POST["files"][$i]]); } } echo $L->sprintf($L->say['_successupl'], '<a href="ftp://' . $_POST["login"] . ':' . $_POST["password"] . '@' . $_POST["host"] . ':' . $_POST["port"] . $_POST["dir"] . '/' . basename($file["name"]) . '"><b>' . basename($file["name"]) . '</b></a>'); echo "<br />" . $L->say['_time'] . ": <b>" . sec2time($time) . "</b><br />" . $L->say['_avg_spd'] . ": <b>" . $speed . " KB/s</b><br /><br />"; } else { echo $L->sprintf($L->say['couldnt_upl_file'], basename($file['name'])) . "<br />"; } } $ftp->quit(); } } } } }
$o = z5c(array('act' => 'ftp', 'flsort', 'ffsort', 'd', 'ft' => 'download', 'rt' => $list_f[$i][0]), z8n($ext, '', '9') . z8v(z8f($disp, 40), '11', z3c($disp, 'f'))); } echo z7i(z7l($o, '19', '2') . z7e(@is_numeric($list_f[$i][1]) ? z7c($list_f[$i][1]) : $list_f[$i][1], '10') . z7l($disp == '..' ? z0q($list_f[$i][0]) : z0r($list_f[$i][0]) . z4n($list_f[$i][0], 'idftp', ($i % 2 ? 'tra' : 'trb') . $jsid), '10'), $i % 2 ? '0' : '1', ($i % 2 ? 'tra' : 'trb') . $jsid); $jsid++; } echo z10w() . z5j() . z7g() . z7u() . z10w(); echo z9m('2') . z7p() . z7k('', '4') . z0p('idloc', 'ltall', z9b('act') . z9b('flsort') . z9b('ffsort') . z9b('d') . z9b('ftpmloc', '1'), array('' => z9s("66"), 'upload' => z9s("197"), 'delete' => z9s("199"))) . z7g() . z7k('', '4') . z0p('idftp', 'rtall', z9b('act') . z9b('flsort') . z9b('ffsort') . z9b('d') . z9b('ftpmrem', '1'), array('' => z9s("66"), 'download' => z9s("198"), 'delete' => z9s("199"))) . z7g() . z7u() . z10w(); } else { echo z2b(z9s("185") . z9c() . ($hmsg != '' ? ' : ' . $hmsg : '')); echo z6d() . z10e(z7i(z5c(array("act" => "ftp", "d"), z6x(z8e(z9s("186")) . z6i("ftp_server", $ftp_server, '5') . z6i("ftp_port", $ftp_port, '6')) . z6x(z8e(z9s("187")) . z6i("ftp_username", $ftp_username, '5')) . z6x(z8e(z9s("188")) . z6i("ftp_password", $ftp_password, '5') . z8v(z9s("189"), '7') . ' ' . z5y("ftp_passive1", z9s("190"), "ftp_passive")))), '2') . z6d(); $dmsg = $umsg = ''; if (!@empty($ftp_server) && !@empty($ftp_port) && !@empty($ftp_username) && !@empty($ftp_password) && @isset($ftp_quickaction)) { $ftp = new ftp($ftp_server, $ftp_port, $ftp_username, $ftp_password, $ftp_passive); if ($ftp->loggedOn) { if ($ftp_quickaction == "upload") { $umsg = $ftp->put($ftp_remotefile, $ftp_localfile) ? z9s("208") : z9s("209"); } elseif ($ftp_quickaction == "download") { $dmsg = $ftp->get($ftp_remotefile, $ftp_localfile, 1) ? z9s("210") : z9s("211"); } } else { if ($ftp_quickaction == "upload") { $umsg = z9s("191"); } else { $dmsg = z9s("191"); } } } echo z2b(array(z9s("200") . z9c() . ($dmsg != '' ? " : " . $dmsg : ''), z9s("201") . z9c() . ($umsg != '' ? " : " . $umsg : '')), '46'); echo z10e(z9f(z9j(z5c(array('act' => 'ftp', 'ftp_quickaction' => 'download', 'd'), z10e(z5n() . z7i(z5t(z9s("202")) . z9j(z6i('ftp_server', $ftp_server, '2') . z6i('ftp_port', $ftp_port, '6'))) . z7i(z5t(z9s("203")) . z9j(z6i('ftp_username', $ftp_username, '4') . z6i('ftp_password', $ftp_password, '5'))) . z7i(z5t(z9s("204")) . z9j(z6i('ftp_remotefile', $ftp_remotefile, '0'))) . z7i(z5t(z9s("205")) . z9j(z6i('ftp_localfile', $ftp_localfile, '0'))) . z7i(z5t('') . z9j(z8v(z9s("207"), '7') . z5y("ftp_passive2", z9s("190"), "ftp_passive"))) . z5n())), '', '4') . z9j(z5c(array('act' => 'ftp', 'ftp_quickaction' => 'upload', 'd'), z10e(z5n() . z7i(z5t(z9s("202")) . z9j(z6i('ftp_server', $ftp_server, '2') . z6i('ftp_port', $ftp_port, '6'))) . z7i(z5t(z9s("203")) . z9j(z6i('ftp_username', $ftp_username, '4') . z6i('ftp_password', $ftp_password, '5'))) . z7i(z5t(z9s("205")) . z9j(z6i('ftp_localfile', $ftp_localfile, '0'))) . z7i(z5t(z9s("204")) . z9j(z6i('ftp_remotefile', $ftp_remotefile, '0'))) . z7i(z5t('') . z9j(z8v(z9s("206"), '7') . z5y("ftp_passive3", z9s("190"), "ftp_passive"))) . z5n())), '', '46')), '2'); } }