/**
	 *
	 * @return bool
	 */
	public function connect() {
		if ( ! $this->ftp )
			return false;

		$this->ftp->setTimeout(FS_CONNECT_TIMEOUT);

		if ( ! $this->ftp->SetServer($this->options['hostname'], $this->options['port']) ) {
			$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
			return false;
		}

		if ( ! $this->ftp->connect() ) {
			$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
			return false;
		}

		if ( ! $this->ftp->login($this->options['username'], $this->options['password']) ) {
			$this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username']));
			return false;
		}

		$this->ftp->SetType( FTP_BINARY );
		$this->ftp->Passive( true );
		$this->ftp->setTimeout( FS_TIMEOUT );
		return true;
	}
 public function connect()
 {
     require_once 'class-ftp.php';
     $this->ftp = new ftp(false);
     if (!$this->ftp->connect($this->options['host'])) {
         $this->ftp->PushError('connect', "Could not connect to host");
         return false;
     }
     if (!$this->ftp->login($this->options['user'], $this->options['pass'])) {
         $this->ftp->PushError('auth', "Authentication failed");
         return false;
     }
     return true;
 }
示例#3
0
 static function ftp_step()
 {
     echo "hey";
     $result = upgrader::get_all_files();
     require "ftpabstract.php";
     $mstring = "cache/" . time() . ".php";
     file_put_contents(ABSPATH . $mstring, "adi");
     chmod(ABSPATH . $mstring, 0777);
     $ftp = new ftp();
     $ftp->Verbose = TRUE;
     $ftp->LocalEcho = TRUE;
     if (!$ftp->SetServer($_REQUEST['fserver'])) {
         $ftp->quit();
         die("Setting server failed :(\n<br>");
     }
     if (!$ftp->connect()) {
         die("Cannot connect: Refresh and try again\n<br>");
     }
     if (!$ftp->login($_REQUEST['fusername'], $_REQUEST['fpassword'])) {
         $ftp->quit();
         die("Login failed: Refresh and try again\n<br>");
     }
     require 'path.php';
     $finder = new finder();
     $finder->mstring = $mstring;
     $finder->connect($ftp);
     $res = $finder->searcher();
     $dirs = $result['dirs'];
     $phpfiles = $result['phpfiles'];
     $only_files = $result['only_files'];
     $everything = $phpfiles;
     //$result["everything"];
     //  file_put_contents("out.txt", print_r($everything, true));
     $xdirs = \CODOF\Util::get_777s();
     @$ftp->chmod($res, 0777);
     foreach ($everything as $thing) {
         @$ftp->chmod($res . $thing, 0777);
         // echo $res.$thing."<br>";
     }
     upgrader::chmod_array($ftp, $everything, $res, 0777);
     upgrader::direct_upgrade();
     $result = upgrader::get_all_files();
     //get all files after unpacking
     $dirs = $result['dirs'];
     $phpfiles = $result['phpfiles'];
     $only_files = $result['only_files'];
     $everything = $phpfiles;
     //$result["everything"];
     upgrader::chmod_array($ftp, $phpfiles, $res, 0644);
     //PHP FILES
     upgrader::chmod_array($ftp, $dirs, $res, 0755);
     //ALL DIRS
     upgrader::chmod_array($ftp, $xdirs, $res, 0777);
     //CACHE & SITE DIRS
 }
	</form>
	<?php 
    echo foot();
} elseif ($job == 'ftp2') {
    require_once "classes/ftp/class.ftp.php";
    require_once "classes/ftp/class.ftp_" . pemftp_class_module() . ".php";
    $temp = array('ftp_server' => $gpc->get('ftp_server', none), 'ftp_port' => $gpc->get('ftp_port', int), 'ftp_user' => $gpc->get('ftp_user', none), 'ftp_pw' => $gpc->get('ftp_pw', none), 'ftp_path' => $gpc->get('ftp_path', none, DIRECTORY_SEPARATOR));
    $error = false;
    $dataGiven = count(array_unique($temp)) == 5;
    if ($dataGiven) {
        ob_start();
        $ftp = new ftp(true, true);
        if (!$ftp->SetServer($temp['ftp_server'], $temp['ftp_port'])) {
            $error = 'admin_server_port_invalid';
        } else {
            if (!$ftp->connect()) {
                $error = 'admin_cannot_connect_to_ftp_server';
            } else {
                if (!$ftp->login($temp['ftp_user'], $temp['ftp_pw'])) {
                    $ftp->quit();
                    $error = 'admin_cannot_authenticate_at_ftp_server';
                } else {
                    if (!$ftp->chdir($temp['ftp_path']) || !$ftp->file_exists('data/config.inc.php')) {
                        $ftp->quit();
                        $lang->assign('ftp_path', $temp['ftp_path']);
                        $error = 'admin_ftp_directory_does_not_exist';
                    }
                }
            }
        }
        $log = ob_get_contents();
 /**
  * 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;
 }
示例#6
0
<?php

$dataGiven = false;
include 'data/config.inc.php';
if (!empty($config['ftp_server'])) {
    require_once "install/classes/ftp/class.ftp.php";
    $pemftp_class = pemftp_class_module();
    if ($pemftp_class !== null) {
        require_once "install/classes/ftp/class.ftp_{$pemftp_class}.php";
        $ftp = new ftp(false, false);
        if ($ftp->SetServer($config['ftp_server'], $config['ftp_port'])) {
            if ($ftp->connect()) {
                if ($ftp->login($config['ftp_user'], $config['ftp_pw'])) {
                    if ($ftp->chdir($config['ftp_path']) && $ftp->file_exists('data/config.inc.php')) {
                        $dataGiven = true;
                    }
                }
            }
            $ftp->quit();
        }
    }
}
?>
<div class="bbody">
<p>
Before we start the automatic update (file updates, updating CHMODs), you have to read the manual update instructions.
Please follow the steps and do the tasks.
More Information:
<?php 
if (file_exists('_docs/readme.txt')) {
    ?>
示例#7
0
文件: schmod.php 项目: Hezkibel/soft
function ampps_ftp($host, $port, $username, $pass, $cd = false, $pub = '', $pri = '', $passphrase = '')
{
    global $settings;
    if ($settings['protocol'] == 'sftp' && !class_exists('sftp')) {
        include_once '_' . $settings['protocol'] . '.php';
    } elseif ($settings['protocol'] == 'ftps' && !class_exists('ftps')) {
        include_once '_' . $settings['protocol'] . '.php';
    } elseif ($settings['protocol'] == 'ftp' && !class_exists('ftp_base')) {
        include_once '_' . $settings['protocol'] . '.php';
    } elseif ($settings['protocol'] == 'customio' && !class_exists('CustomIO')) {
        include_once '_' . $settings['protocol'] . '.php';
    }
    if ($settings['protocol'] == 'ftp') {
        $ftp = new ftp(FALSE, FALSE);
        if (!$ftp->SetServer($host)) {
            $ftp->quit();
            return 0;
        }
        if (!$ftp->connect()) {
            return -1;
        }
        if (!$ftp->login($username, $pass)) {
            $ftp->quit();
            return -2;
        }
        if (!empty($cd)) {
            if (!$ftp->chdir($cd)) {
                if (!$ftp->chdir(trim($cd, '/'))) {
                    return -3;
                }
                //return -3;
            }
        }
        if (!$ftp->SetType(FTP_AUTOASCII)) {
        }
        if (!$ftp->Passive(TRUE)) {
        }
    }
    if ($settings['protocol'] == 'sftp' || $settings['protocol'] == 'ftps' || $settings['protocol'] == 'customio') {
        if ($settings['protocol'] == 'customio') {
            $ftp = new CustomIO();
        } else {
            $ftp = new $settings['protocol']();
        }
        if ($settings['protocol'] == 'sftp' && !empty($pub) && !empty($pri)) {
            $ftp->auth_pass = 0;
        } else {
            $ftp->auth_pass = 1;
        }
        $ret = $ftp->connect($host, $port, $username, $pass, $pub, $pri, $passphrase);
        if (!is_object($ftp)) {
            return -1;
        }
        if (!$ret) {
            return -2;
        }
        /* if($settings['protocol'] == 'sftp' && (!$ret)){
        			return -2;
        		}
        		
        		if(($settings['protocol'] == 'ftps' || $settings['protocol'] == 'customio') && !$ftp->ftp_conn){
        			return -2;
        		} */
        if (!empty($cd)) {
            if (!$ftp->is_dir($cd)) {
                return -3;
            }
        }
    }
    return $ftp;
}
示例#8
0
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();
                }
            }
        }
    }
}
示例#9
0
文件: upgrade.php 项目: phannack/GCMS
<?php

if (INSTALL_INIT == 'upgrade') {
    $config['ftp_host'] = $_SERVER['SERVER_ADDR'];
    $config['ftp_port'] = empty($config['ftp_port']) ? 21 : $config['ftp_port'];
    $config['ftp_root'] = empty($config['ftp_root']) ? 'public_html' : $config['ftp_root'];
    $ftp = false;
    if (!empty($config['ftp_username']) && !empty($config['ftp_password'])) {
        $ftp = new ftp($config['ftp_host'], $config['ftp_username'], $config['ftp_password'], $config['ftp_root'], $config['ftp_port']);
    }
    if ($ftp && $ftp->connect() && $ftp->is_dir($config['ftp_root'])) {
        $_SESSION['ftp_root'] = $config['ftp_root'];
        include ROOT_PATH . 'admin/install/upgrade1.php';
    } else {
        echo '<h2>ยินดีต้อนรับสู่การปรับรุ่นของ GCMS เวอร์ชั่น ' . $version . '</h2>';
        echo '<p><em>เราตรวจพบโฟลเดอร์ <strong>install/</strong> บนเซิร์ฟเวอร์ของคุณ และตรวจพบ <strong>GCMS</strong> เวอร์ชั่นใหม่บนเซิร์ฟเวอร์ของคุณ</em> และต้องการการปรับรุ่น</p>';
        echo '<h3>ระบุที่อยู่ FTP ของโฮสต์</h3>';
        echo '<p>ก่อนอื่นเราแนะนำให้คุณระบุค่ากำหนดต่างๆของ FTP Server ของคุณ FTP จะช่วยให้คุณจัดการกับไฟล์และไดเร็คทอรี่บน GCMS ได้ง่ายขึ้น ถ้าคุณไม่รู้ค่ากำหนดเหล่านี้ คุณสามารถข้ามขั้นตอนนี้ไปก่อนได้</p>';
        echo '<form method=post action=index.php autocomplete=off>';
        echo '<p class=row><label for=ftp_host>โฮสต์</label><input type=text size=70 id=ftp_host name=ftp_host value="' . (!empty($_SESSION['ftp_host']) ? $_SESSION['ftp_host'] : $config['ftp_host']) . '"></p>';
        echo '<p class="row comment">FTP โดเมน เช่น ftp.domain.tld หรือ ที่อยู่ IP ของโฮสต์</p>';
        echo '<p class=row><label for=ftp_username>ชื่อผู้ใช้</label><input type=text size=70 id=ftp_username name=ftp_username value="' . (!empty($_SESSION['ftp_username']) ? $_SESSION['ftp_username'] : $config['ftp_username']) . '"></p>';
        echo '<p class="row comment">ชื่อผู้ใช้ของ FTP</p>';
        echo '<p class=row><label for=ftp_password>รหัสผ่าน</label><input type=password size=70 id=ftp_password name=ftp_password value="' . (!empty($_SESSION['ftp_password']) ? $_SESSION['ftp_password'] : $config['ftp_password']) . '"></p>';
        echo '<p class="row comment">รหัสผ่านของ FTP</p>';
        echo '<p class=row><label for=ftp_root>FTP Root</label><input type=text size=70 id=ftp_root name=ftp_root value="' . (!empty($_SESSION['ftp_root']) ? $_SESSION['ftp_root'] : $config['ftp_root']) . '"></p>';
        echo '<p class="row comment">ไดเรคทอรี่เริ่มต้นของของโฮสต์เช่น public_html หรือ www</p>';
        echo '<p class=row><label for=ftp_port>พอร์ต</label><input type=text size=70 id=ftp_port name=ftp_port value="' . (!empty($_SESSION['ftp_port']) ? $_SESSION['ftp_port'] : $config['ftp_port']) . '"></p>';
        echo '<p class="row comment">FTP พอร์ต (ค่าปกติคือ 20)</p>';
        echo '<input type=hidden name=step value=1>';
        echo '<p><input class=button type=submit value="ดำเนินการต่อ."></p>';
示例#10
0
function getftpurl($host, $port, $url, $saveToFile = 0)
{
    global $nn, $lastError, $PHP_SELF, $FtpBytesTotal, $FtpBytesReceived, $FtpTimeStart, $FtpChunkSize, $options;
    $ftp = new ftp(FALSE, FALSE);
    $server = "{$host}:{$port}";
    if (empty($host) || empty($port) || !$ftp->SetServer($host, (int) $port)) {
        $ftp->quit();
        $lastError = sprintf(lang(79), $server);
        return FALSE;
    } else {
        if (!$ftp->connect()) {
            $ftp->quit();
            $lastError = sprintf(lang(79), $server);
            return FALSE;
        } else {
            if (!$ftp->login()) {
                $ftp->quit();
                $lastError = lang(80);
                return FALSE;
            } else {
                echo '<p>';
                printf(lang(81), $server);
                echo '<br />';
                //$ftp->Passive(FALSE);
                $tmp = explode("/", $url);
                $ftp_file = array_pop($tmp);
                $ftp_dir = implode('/', $tmp);
                $ftp->chdir($ftp_dir);
                $fileSize = $FtpBytesTotal = $ftp->filesize($ftp_file);
                $FtpChunkSize = round($fileSize / 333);
                if (strpos($saveToFile, '?') !== false) {
                    $saveToFile = substr($saveToFile, 0, strpos($saveToFile, '?'));
                }
                if ($options['file_size_limit'] > 0) {
                    if ($fileSize > $options['file_size_limit'] * 1024 * 1024) {
                        $lastError = lang(336) . bytesToKbOrMbOrGb($options['file_size_limit'] * 1024 * 1024) . ".";
                        return false;
                    }
                }
                if (!empty($options['rename_prefix'])) {
                    $File_Name = $options['rename_prefix'] . '_' . basename($saveToFile);
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                if (!empty($options['rename_suffix'])) {
                    $ext = strrchr(basename($saveToFile), '.');
                    $before_ext = explode($ext, basename($saveToFile));
                    $File_Name = $before_ext[0] . '_' . $options['rename_suffix'] . $ext;
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                if ($options['rename_underscore']) {
                    $File_Name = str_replace(array(' ', '%20'), '_', basename($saveToFile));
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                $filetype = strrchr($saveToFile, '.');
                if (is_array($options['forbidden_filetypes']) && in_array(strtolower($filetype), $options['forbidden_filetypes'])) {
                    if ($options['forbidden_filetypes_block']) {
                        html_error(sprintf(lang(82), $filetype));
                    }
                    $saveToFile = str_replace($filetype, $options['rename_these_filetypes_to'], $saveToFile);
                }
                if (@file_exists($saveToFile) && $options['bw_save']) {
                    // Skip in audl.
                    if (isset($_GET['audl'])) {
                        echo '<script type="text/javascript">parent.nextlink();</script>';
                    }
                    html_error(lang(99) . ': ' . link_for_file($saveToFile));
                } elseif (@file_exists($saveToFile)) {
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . time() . '_' . basename($saveToFile);
                }
                printf(lang(83), basename($saveToFile), bytesToKbOrMbOrGb($fileSize));
                echo "<br />";
                require_once TEMPLATE_DIR . '/transloadui.php';
                $FtpTimeStart = getmicrotime();
                if ($ftp->get($ftp_file, $saveToFile)) {
                    $ftp->quit();
                    $time = getmicrotime() - $FtpTimeStart;
                    return array('time' => sec2time(round($time)), 'speed' => @round($FtpBytesTotal / 1024 / $time, 2), 'received' => TRUE, 'size' => bytesToKbOrMbOrGb($fileSize), 'bytesReceived' => $FtpBytesReceived, 'bytesTotal' => $FtpBytesTotal, 'file' => $saveToFile);
                }
                $ftp->quit();
                return FALSE;
            }
        }
    }
}
示例#11
0
            $server->put($dest . '/' . $v['name'], $content);
        }
        $i++;
    }
}
if ($_POST['path'] == 'root') {
    $_POST['path'] = '';
}
$site = $_GET['site'];
if ($_POST['server_type']) {
    $options = array('site' => $_POST);
}
switch ($server_type) {
    case 'ftp':
        $server = new ftp();
        $result = $server->connect($host, $username, $password, $port, $dir, array('pasv' => $pasv));
        if ($result === false) {
            print_r($server->ftp_log);
            exit;
        }
        break;
    case 'sftp':
        $server = new sftp();
        $result = $server->connect($host, $username, $password, $port, $dir);
        if ($result === false) {
            print_r($server->ftp_log);
            exit;
        }
        break;
    default:
        $server = new local();
示例#12
0
function getftpurl($host, $port, $url, $saveToFile = 0)
{
    global $nn, $lastError, $PHP_SELF, $AUTH, $IS_FTP, $FtpBytesTotal, $FtpBytesReceived, $FtpTimeStart, $FtpChunkSize, $options;
    $ftp = new ftp(FALSE, FALSE);
    if (!$ftp->SetServer($host, (int) $port)) {
        $ftp->quit();
        $server = $host . ':' . $port;
        $lastError = sprintf(lang(79), $server) . "<br />" . '<a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />';
        return FALSE;
    } else {
        if (!$ftp->connect()) {
            $ftp->quit();
            $lastError = sprintf(lang(79), $server) . "<br />" . '<a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />';
            return FALSE;
        } else {
            if (!$ftp->login($AUTH["ftp"]["login"], $AUTH["ftp"]["password"])) {
                $ftp->quit();
                $lastError = lang(80) . "<br />" . '<a href="javascript:history.back(-1);">' . lang(78) . '</a><br /><br />';
                return FALSE;
            } else {
                echo '<p>';
                printf(lang(81), $host);
                echo '<br />';
                //$ftp->Passive(FALSE);
                $tmp = explode("/", $url);
                $ftp_file = array_pop($tmp);
                $ftp_dir = implode("/", $tmp);
                $ftp->chdir($ftp_dir);
                $fileSize = $FtpBytesTotal = $ftp->filesize($ftp_file);
                $FtpChunkSize = round($fileSize / 333);
                list($saveToFile, $tmp) = explode('?', $saveToFile);
                if (!empty($options['rename_prefix'])) {
                    $File_Name = $options['rename_prefix'] . '_' . basename($saveToFile);
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                if (!empty($options['rename_suffix'])) {
                    $ext = strrchr(basename($saveToFile), ".");
                    $before_ext = explode($ext, basename($saveToFile));
                    $File_Name = $before_ext[0] . '_' . $options['rename_suffix'] . $ext;
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                if ($options['rename_underscore']) {
                    $File_Name = str_replace(array(' ', '%20'), '_', basename($saveToFile));
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                $filetype = strrchr($saveToFile, ".");
                if (is_array($options['forbidden_filetypes']) && in_array(strtolower($filetype), $options['forbidden_filetypes'])) {
                    if ($options['forbidden_filetypes_block']) {
                        html_error(sprintf(lang(82), $filetype));
                    } else {
                        $saveToFile = str_replace($filetype, $options['rename_these_filetypes_to'], $saveToFile);
                    }
                }
                if (file_exists($saveToFile)) {
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . time() . "_" . basename($saveToFile);
                }
                printf(lang(83), $saveToFile, bytesToKbOrMbOrGb($fileSize));
                echo "<br />";
                ?>
<br />
<table cellspacing="0" cellpadding="0" style="FONT-FAMILY: Tahoma; FONT-SIZE: 11px;">
<tr>
<td></td>
<td>
<div class="progressouter">
<div id="progress" class="ftpprogress">
</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 />
<div id="resume" align="center" style="FONT-FAMILY: Tahoma; FONT-SIZE: 11px;"></div>
<script type="text/javascript">
/* <![CDATA[ */
function pr(percent, received, speed){
	document.getElementById("received").innerHTML = '<b>' + received + '</b>';
	document.getElementById("percent").innerHTML = '<b>' + percent + '%</b>';
	document.getElementById("progress").style.width = percent + '%';
	document.getElementById("speed").innerHTML = '<b>' + speed + ' KB/s</b>';
	document.title = 'Downloaded ' + percent + '%';
	return true;
	}

	function mail(str, field) {
	document.getElementById("mailPart." + field).innerHTML = str;
	return true;
	}
/* ]]> */
</script>
<br />
<?php 
                $FtpTimeStart = getmicrotime();
                if ($ftp->get($ftp_file, $saveToFile)) {
                    return array("time" => sec2time(round($time)), "speed" => @round($FtpBytesTotal / 1024 / (getmicrotime() - $FtpTimeStart), 2), "received" => TRUE, "size" => bytesToKbOrMbOrGb($fileSize), "bytesReceived" => $FtpBytesReceived, "bytesTotal" => $FtpBytesTotal, "file" => $saveToFile);
                } else {
                    return FALSE;
                }
                $ftp->quit();
            }
        }
    }
}
示例#13
0
function getftpurl($host, $port, $url, $saveToFile = 0)
{
    global $nn, $lastError, $PHP_SELF, $FtpBytesTotal, $FtpBytesReceived, $FtpTimeStart, $FtpChunkSize, $options, $L;
    $ftp = new ftp(FALSE, FALSE);
    $server = "{$host}:{$port}";
    if (empty($host) || empty($port) || !$ftp->SetServer($host, (int) $port)) {
        $ftp->quit();
        $lastError = $L->sprintf($L->say['couldnt_establish_con'], $server) . "<br />" . '<a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />';
        return FALSE;
    } else {
        if (!$ftp->connect()) {
            $ftp->quit();
            $lastError = $L->sprintf($L->say['couldnt_establish_con'], $server) . "<br />" . '<a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />';
            return FALSE;
        } else {
            if (!$ftp->login()) {
                $ftp->quit();
                $lastError = $L->say['incorrect_userpass'] . "<br />" . '<a href="javascript:history.back(-1);">' . $L->say['_back'] . '</a><br /><br />';
                return FALSE;
            } else {
                echo '<p>';
                $L->sprintf($L->say['_con'], $host);
                echo '<br />';
                //$ftp->Passive(FALSE);
                $tmp = explode("/", $url);
                $ftp_file = array_pop($tmp);
                $ftp_dir = implode("/", $tmp);
                $ftp->chdir($ftp_dir);
                $fileSize = $FtpBytesTotal = $ftp->filesize($ftp_file);
                $FtpChunkSize = round($fileSize / 333);
                if (strpos($saveToFile, '?') !== false) {
                    $saveToFile = substr($saveToFile, 0, strpos($saveToFile, '?'));
                }
                if ($options['maxlimitsize'] > 0) {
                    if ($fileSize > $options['maxlimitsize'] * 1024 * 1024) {
                        $lastError = $L->sprintf($L->say['_sorry_tobig'], bytesToKbOrMbOrGb($fileSize), $options["maxlimitsize"]);
                        return false;
                    }
                }
                if ($options['minlimitsize'] > 0) {
                    if ($fileSize < $options['minlimitsize'] * 1024 * 1024) {
                        $lastError = $L->sprintf($L->say['_sorry_tosmall'], bytesToKbOrMbOrGb($fileSize), $options["minlimitsize"]);
                        return false;
                    }
                }
                if (!empty($options["add_ext_5city"]) || !empty($options['rename_suffix']) || !empty($options['rename_prefix']) || $options['rename_underscore']) {
                    if (!empty($options["add_ext_5city"])) {
                        $ext = str_replace(".", "", $options["add_ext_5city"]);
                        $File_Name = basename($saveToFile) . "." . $options["add_ext_5city"];
                    }
                    if (!empty($options['rename_prefix'])) {
                        $File_Name = $options['rename_prefix'] . '_' . basename($saveToFile);
                    }
                    if (!empty($options['rename_suffix'])) {
                        $ext = strrchr(basename($saveToFile), ".");
                        $before_ext = explode($ext, basename($saveToFile));
                        $File_Name = $before_ext[0] . '_' . $options['rename_suffix'] . $ext;
                    }
                    if ($options['rename_underscore']) {
                        $File_Name = str_replace(array(' ', '%20'), '_', basename($saveToFile));
                    }
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name;
                }
                $filetype = strrchr($saveToFile, ".");
                if (is_array($options['forbidden_filetypes']) && in_array(strtolower($filetype), $options['forbidden_filetypes'])) {
                    if ($options['forbidden_filetypes_block']) {
                        html_error($L->sprintf($L->say['_forbid_filetype'], $filetype));
                    } else {
                        $saveToFile = str_replace($filetype, $options['rename_these_filetypes_to'], $saveToFile);
                    }
                }
                if (file_exists($saveToFile)) {
                    $saveToFile = dirname($saveToFile) . PATH_SPLITTER . time() . "_" . basename($saveToFile);
                }
                if (!empty($options["add_ext_5city"])) {
                    $ext = "." . get_extension(basename($saveToFile));
                    $File_Name = str_replace($ext, "", basename($saveToFile));
                }
                echo $L->sprintf($L->say['_saveprogres'], $saveToFile, $ext, bytesToKbOrMbOrGb($fileSize)) . "<br />";
                require_once TEMPLATE_DIR . 'transloadui.php';
                $FtpTimeStart = getmicrotime();
                if ($ftp->get($ftp_file, $saveToFile)) {
                    $ftp->quit();
                    $time = getmicrotime() - $FtpTimeStart;
                    return array('time' => sec2time(round($time)), 'speed' => @round($FtpBytesTotal / 1024 / $time, 2), 'received' => TRUE, 'size' => bytesToKbOrMbOrGb($fileSize), 'bytesReceived' => $FtpBytesReceived, 'bytesTotal' => $FtpBytesTotal, 'file' => $saveToFile);
                }
                $ftp->quit();
                return FALSE;
            }
        }
    }
}
示例#14
0
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();
                }
            }
        }
    }
}