Exemple #1
0
function sftp_connect()
{
    global $_SGLOBAL;
    @set_time_limit(0);
    $func = $_SGLOBAL['setting']['ftpssl'] && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
    if ($func == 'ftp_connect' && !function_exists('ftp_connect')) {
        runlog('FTP', "FTP NOT SUPPORTED.", 0);
    }
    if ($ftpconnid = @$func($_SGLOBAL['setting']['ftphost'], intval($_SGLOBAL['setting']['ftpport']), 20)) {
        if ($_SGLOBAL['setting']['ftptimeout'] && function_exists('ftp_set_option')) {
            @ftp_set_option($ftpconnid, FTP_TIMEOUT_SEC, $_SGLOBAL['setting']['ftptimeout']);
        }
        if (sftp_login($ftpconnid, $_SGLOBAL['setting']['ftpuser'], $_SGLOBAL['setting']['ftppassword'])) {
            if ($_SGLOBAL['setting']['ftppasv']) {
                sftp_pasv($ftpconnid, TRUE);
            }
            if (sftp_chdir($ftpconnid, $_SGLOBAL['setting']['ftpdir'])) {
                return $ftpconnid;
            } else {
                runlog('FTP', "CHDIR '{$_SGLOBAL[setting][ftpdir]}' ERROR.", 0);
            }
        } else {
            runlog('FTP', '530 NOT LOGGED IN.', 0);
        }
    } else {
        runlog('FTP', "COULDN'T CONNECT TO {$_SGLOBAL[setting][ftphost]}:{$_SGLOBAL[setting][ftpport]}.", 0);
    }
    sftp_close($ftpconnid);
    return -1;
}
Exemple #2
0
 function mconnect($fhost, $fuser, $fpassword, $fpath, $fport = 21, $fpasv = 0, $timeout = 0, $fssl = 0)
 {
     $func = $fssl && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
     if ($func == 'ftp_connect' && !function_exists('ftp_connect')) {
         $this->conn_id = 0;
         return -1;
     }
     if (!($this->conn_id = @$func($fhost, $fport, 20))) {
         $this->conn_id = 0;
         return -2;
     }
     if ($timeout && function_exists('ftp_set_option')) {
         @ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $timeout);
     }
     if (@(!ftp_login($this->conn_id, $fuser, $fpassword))) {
         $this->conn_id = 0;
         return -3;
     }
     @ftp_pasv($this->conn_id, $fpasv ? true : false);
     if (!$this->mchdir($fpath)) {
         $this->conn_id = 0;
         return -4;
     }
     return $this->conn_id;
 }
	protected function _settimeout($sock) {
		if(!ftp_set_option($sock, FTP_TIMEOUT_SEC, $this->timeout)) {
			$this->pushError('_settimeout', 'ftp set send timeout');
			$this->_quit();
			return false;
		}
		return true;
	}
 private function connect()
 {
     //prepare connection
     $this->connection = ftp_connect($this->host, $this->port);
     //login to ftp server
     $loginResponse = ftp_login($this->connection, $this->user, $this->pass);
     if (!$this->connection || !$loginResponse) {
         return false;
     }
     ftp_pasv($this->connection, $this->passive);
     ftp_set_option($this->connection, FTP_TIMEOUT_SEC, 300);
 }
function dftp_connect($ftphost, $ftpuser, $ftppass, $ftppath, $ftpport = 21, $ftpssl = 0, $silent = 0)
{
    global $ftp;
    @set_time_limit(0);
    $ftphost = wipespecial($ftphost);
    $ftpport = intval($ftpport);
    $ftpssl = intval($ftpssl);
    $ftp['timeout'] = intval($ftp['timeout']);
    $func = $ftpssl && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
    if ($func == 'ftp_connect' && !function_exists('ftp_connect')) {
        if ($silent) {
            return -4;
        } else {
            errorlog('FTP', "FTP not supported.", 0);
        }
    }
    if ($ftp_conn_id = @$func($ftphost, $ftpport, 20)) {
        if ($ftp['timeout'] && function_exists('ftp_set_option')) {
            @ftp_set_option($ftp_conn_id, FTP_TIMEOUT_SEC, $ftp['timeout']);
        }
        if (dftp_login($ftp_conn_id, $ftpuser, $ftppass)) {
            if ($ftp['pasv']) {
                dftp_pasv($ftp_conn_id, TRUE);
            }
            if (dftp_chdir($ftp_conn_id, $ftppath)) {
                return $ftp_conn_id;
            } else {
                if ($silent) {
                    return -3;
                } else {
                    errorlog('FTP', "Chdir '{$ftppath}' error.", 0);
                }
            }
        } else {
            if ($silent) {
                return -2;
            } else {
                errorlog('FTP', '530 Not logged in.', 0);
            }
        }
    } else {
        if ($silent) {
            return -1;
        } else {
            errorlog('FTP', "Couldn't connect to {$ftphost}:{$ftpport}.", 0);
        }
    }
    dftp_close($ftp_conn_id);
    return -1;
}
Exemple #6
0
 /**
  * Establish ftp connection
  *
  * @param $config
  * @return resource
  * @throws \Exception
  */
 public function connect($config)
 {
     if (!isset($config['port'])) {
         $config['port'] = 21;
     }
     $connectionId = ftp_connect($config['host'], $config['port']);
     $loginResponse = ftp_login($connectionId, $config['username'], $config['password']);
     ftp_pasv($connectionId, $config['passive']);
     ftp_set_option($connectionId, FTP_TIMEOUT_SEC, 300);
     if (!$connectionId || !$loginResponse) {
         throw new \Exception('FTP connection has failed!');
     }
     return $connectionId;
 }
Exemple #7
0
 /**
  * FTP-ftp连接
  *
  * @param array  $config 配置
  *
  * @return bool
  */
 public function connect(array $config)
 {
     $port = isset($config['port']) ? (int) $config['port'] : 21;
     //端口号
     $this->linkid = ftp_connect($config['service'], $port);
     if (!$this->linkid) {
         return false;
     }
     @ftp_set_option($this->linkid, FTP_TIMEOUT_SEC, $this->timeout);
     if (@(!ftp_login($this->linkid, $config['username'], $config['password']))) {
         return false;
     }
     return true;
 }
Exemple #8
0
 /**
  * Creates a new connection to an FTP server.
  *
  * @param array $config
  *
  * @throws \Exception
  *
  * @return resource
  */
 public function connect($config)
 {
     if (!isset($config['port'])) {
         $config['port'] = 21;
     }
     if (!isset($config['passive'])) {
         $config['passive'] = true;
     }
     $connection = ftp_connect($config['host'], $config['port']);
     $response = ftp_login($connection, $config['user'], $config['pass']);
     ftp_pasv($connection, $config['passive']);
     ftp_set_option($connection, FTP_TIMEOUT_SEC, 300);
     if (!$connection || !$response) {
         throw new Exception('FTP Connection Failed');
     }
     return $connection;
 }
 public function connect($host, $login, $password)
 {
     if (!parent::connect($host, $login, $password)) {
         return false;
     }
     if (empty($this->port)) {
         $this->port = 21;
     }
     $this->handle = $this->ssl && function_exists('ftp_ssl_connect') ? @ftp_ssl_connect($this->host, $this->port, $this->timeout) : @ftp_connect($this->host, $this->port, $this->timeout);
     if ($this->handle && @ftp_login($this->handle, $this->login, $this->password)) {
         @ftp_pasv($this->handle, true);
         if (@ftp_get_option($this->handle, FTP_TIMEOUT_SEC) < $this->timeout) {
             @ftp_set_option($this->handle, FTP_TIMEOUT_SEC, $this->timeout);
         }
         $this->connected = true;
         return true;
     }
     return false;
 }
Exemple #10
0
 function connect($host, $port = null, $user = '', $pass = '')
 {
     $this->disconnect();
     $this->_host = $host;
     $this->_port = $port;
     if (in_array($user, array('', null, false), true)) {
         $user = '******';
         $pass = '******';
     }
     $this->_user = $user;
     $this->_pass = $pass;
     if (!extension_loaded('ftp')) {
         gs_log(GS_LOG_WARNING, 'ftp extension for PHP not available');
         $this->_conn_failed = true;
         return false;
     }
     if (!preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $this->_host)) {
         $ips = getHostByNameL($this->_host);
         # for some strange reason this is a lot faster than to
         # leave the lookup up to ftp_connect()
         if (!is_array($ips) || count($ips) < 1) {
             gs_log(GS_LOG_WARNING, 'Failed to resolve "' . $this->_host . '"');
             $this->_conn_failed = true;
             return false;
         }
         $this->_host = $ips[0];
     }
     $this->_conn = ftp_connect($this->_host, $this->_port, 4);
     if (!$this->_conn) {
         gs_log(GS_LOG_NOTICE, 'Failed to connect to ftp://' . $this->_host);
         $this->_conn_failed = true;
         return false;
     }
     @ftp_set_option($this->_conn, FTP_TIMEOUT_SEC, 3);
     if (!@ftp_login($this->_conn, $this->_user, $this->_pass)) {
         gs_log(GS_LOG_NOTICE, 'Failed to log in at ftp://' . $this->_host);
         $this->_conn_failed = true;
         @ftp_close($this->_conn);
         return false;
     }
     $this->_connected = true;
     return true;
 }
Exemple #11
0
 public function connect()
 {
     $this->conn_id = ftp_connect($this->host, $this->port, 30);
     if ($this->conn_id === false) {
         return false;
     }
     $result = ftp_login($this->conn_id, $this->username, $this->password);
     if ($result == true) {
         ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $this->timeout);
         if ($this->passive == true) {
             ftp_pasv($this->conn_id, true);
         } else {
             ftp_pasv($this->conn_id, false);
         }
         $this->system_type = ftp_systype($this->conn_id);
         return true;
     } else {
         return false;
     }
 }
Exemple #12
0
 /**
  * 连接FTP
  * @param string $server 服务器名
  * @param integer $port 服务器端口
  * @param string $username 用户名
  * @param string $password 密码
  * @return boolean
  */
 public function connect($server, $username, $password, $port = 21)
 {
     //参数分析
     if (!$server || !$username || !$password) {
         return false;
     }
     $this->link = ftp_connect($server, $port);
     if (!$this->link) {
         $this->falseMessage = '不能连接到FTP!';
         return false;
     }
     @ftp_set_option($this->link, FTP_TIMEOUT_SEC, $this->timeout);
     if (@(!ftp_login($this->link, $username, $password))) {
         $this->falseMessage = '不能登录到FTP!请检查用户名和密码。';
         return false;
     }
     //打开被动模拟
     @ftp_pasv($this->link, 1);
     return true;
 }
Exemple #13
0
 function fconnect($ftphost, $ftpport, $ftpusername, $ftppassword, $ftppath, $ftpssl = 0, $pasv = 0, $tranmode = 0, $timeout = 0, $checkftp = 0)
 {
     $ftphost = $this->wipespecial($ftphost);
     $func = $ftpssl && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
     $this->ftpconnectid = @$func($ftphost, $ftpport, 20);
     if (!$this->ftpconnectid) {
         if ($checkftp == 1) {
             return 'HostFail';
         }
         echo "Fail to connect ftp host!";
         exit;
     }
     if ($timeout && function_exists('ftp_set_option')) {
         @ftp_set_option($this->ftpconnectid, FTP_TIMEOUT_SEC, $timeout);
     }
     $login = $this->fLogin($ftpusername, $ftppassword);
     if (!$login) {
         if ($checkftp == 1) {
             $this->fExit();
             return 'UserFail';
         }
         echo "The username/password for ftp is error!";
         $this->fExit();
         exit;
     }
     if ($pasv) {
         $this->fPasv(TRUE);
     }
     $ftppath = empty($ftppath) ? '/' : $ftppath;
     $chdir = $this->fChdir($ftppath);
     if (!$chdir) {
         if ($checkftp == 1) {
             $this->fExit();
             return 'PathFail';
         }
         echo "The path for ftp is error!";
         $this->fExit();
         exit;
     }
     $this->ftptranmode = $tranmode ? FTP_ASCII : FTP_BINARY;
 }
 function login()
 {
     require SYSTEM_ROOT . '/config.remote.php';
     if (!(self::$cid = @ftp_connect($ftp_host, $ftp_port, $ftp_timeout))) {
         //self::halt("Can't connect to FTP server on '$ftp_host'");
         return false;
     }
     if (!@ftp_login(self::$cid, $ftp_user, $ftp_pass)) {
         //self::halt("Can't login to FTP server on '$ftp_host' with username '$ftp_user'");
         return false;
     }
     self::$root = $ftp_root;
     $ftp_host = $ftp_user = $ftp_pass = $ftp_root = $ftp_port = NULL;
     ftp_set_option(self::$cid, FTP_TIMEOUT_SEC, $ftp_timeout);
     ftp_pasv(self::$cid, true);
     if (self::islogin()) {
         return true;
     } else {
         //self::halt("Can't query from FTP server");
         return false;
     }
 }
 public function connect()
 {
     if (isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect')) {
         $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
     } else {
         $this->link = @ftp_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
     }
     if (!$this->link) {
         $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
         return false;
     }
     if (!@ftp_login($this->link, $this->options['username'], $this->options['password'])) {
         $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username']));
         return false;
     }
     // Set the Connection to use Passive FTP
     @ftp_pasv($this->link, true);
     if (@ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FS_TIMEOUT) {
         @ftp_set_option($this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT);
     }
     return true;
 }
Exemple #16
0
 function connect()
 {
     if (isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect')) {
         $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], $this->options['connect_timeout']);
     } else {
         $this->link = @ftp_connect($this->options['hostname'], $this->options['port'], $this->options['connect_timeout']);
     }
     if (!$this->link) {
         $this->errors->add('connect', sprintf('Could not connect to FTP server %s:%s', $this->options['hostname'], $this->options['port']));
         return false;
     }
     if (!@ftp_login($this->link, $this->options['username'], $this->options['password'])) {
         $this->errors->add('auth', 'The username and/or password is incorrect.');
         return false;
     }
     //Set the Connection to use Passive FTP
     @ftp_pasv($this->link, true);
     if (@ftp_get_option($this->link, FTP_TIMEOUT_SEC) < $this->options['connection_timeout']) {
         @ftp_set_option($this->link, FTP_TIMEOUT_SEC, $this->options['connection_timeout']);
     }
     return true;
 }
Exemple #17
0
 public function connect()
 {
     $time_start = time();
     $this->conn_id = ftp_connect($this->host, $this->port, 20);
     if ($this->conn_id) {
         $result = ftp_login($this->conn_id, $this->username, $this->password);
     }
     if (!empty($result)) {
         ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $this->timeout);
         ftp_pasv($this->conn_id, $this->passive);
         $this->system_type = ftp_systype($this->conn_id);
         return true;
     } elseif (time() - $time_start > 19) {
         global $updraftplus_admin;
         if (isset($updraftplus_admin->logged) && is_array($updraftplus_admin->logged)) {
             $updraftplus_admin->logged[] = sprintf(__('The %s connection timed out; if you entered the server correctly, then this is usually caused by a firewall blocking the connection - you should check with your web hosting company.', 'updraftplus'), 'FTP');
         } else {
             global $updraftplus;
             $updraftplus->log(sprintf(__('The %s connection timed out; if you entered the server correctly, then this is usually caused by a firewall blocking the connection - you should check with your web hosting company.', 'updraftplus'), 'FTP'), 'error');
         }
     }
     return false;
 }
Exemple #18
0
<?php

require 'server.inc';
$ftp = ftp_connect('127.0.0.1', $port);
ftp_login($ftp, 'user', 'pass');
if (!$ftp) {
    die("Couldn't connect to the server");
}
ftp_set_option($ftp, FTP_AUTOSEEK, false);
$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "ftp_fget_basic1.txt";
$handle = fopen($local_file, 'w');
var_dump(ftp_fget($ftp, $handle, 'fget.txt', FTP_ASCII, FTP_AUTORESUME));
var_dump(file_get_contents($local_file));
@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "ftp_fget_basic1.txt");
 protected function createFTPLink()
 {
     // If connexion exist and is still connected
     if (is_array($_SESSION["FTP_CONNEXIONS"]) && array_key_exists($this->repositoryId, $_SESSION["FTP_CONNEXIONS"]) && @ftp_systype($_SESSION["FTP_CONNEXIONS"][$this->repositoryId])) {
         AJXP_Logger::debug("Using stored FTP Session");
         return $_SESSION["FTP_CONNEXIONS"][$this->repositoryId];
     }
     AJXP_Logger::debug("Creating new FTP Session");
     $link = FALSE;
     //Connects to the FTP.
     if ($this->secure) {
         $link = @ftp_ssl_connect($this->host, $this->port);
     } else {
         $link = @ftp_connect($this->host, $this->port);
     }
     if (!$link) {
         throw new AJXP_Exception("Cannot connect to FTP server!");
     }
     //register_shutdown_function('ftp_close', $link);
     @ftp_set_option($link, FTP_TIMEOUT_SEC, 10);
     if (!@ftp_login($link, $this->user, $this->password)) {
         throw new AJXP_Exception("Cannot login to FTP server with user {$this->user}");
     }
     if (!$this->ftpActive) {
         @ftp_pasv($link, true);
         global $_SESSION;
         $_SESSION["ftpPasv"] = "true";
     }
     if (!is_array($_SESSION["FTP_CONNEXIONS"])) {
         $_SESSION["FTP_CONNEXIONS"] = array();
     }
     $_SESSION["FTP_CONNEXIONS"][$this->repositoryId] = $link;
     return $link;
 }
Exemple #20
0
 /**
  * Method to connect to a FTP server
  *
  * @access public
  * @param string $host Host to connect to [Default: 127.0.0.1]
  * @param string $port Port to connect on [Default: port 21]
  * @return boolean True if successful
  */
 function connect($host = '127.0.0.1', $port = 21)
 {
     // Initialise variables.
     $errno = null;
     $err = null;
     // If already connected, return
     if (is_resource($this->_conn)) {
         return true;
     }
     // If native FTP support is enabled lets use it...
     if (FTP_NATIVE) {
         $this->_conn = @ftp_connect($host, $port, $this->_timeout);
         if ($this->_conn === false) {
             JError::raiseWarning('30', JText::sprintf('JLIB_CLIENT_ERROR_JFTP_NO_CONNECT', $host, $port));
             return false;
         }
         // Set the timeout for this connection
         ftp_set_option($this->_conn, FTP_TIMEOUT_SEC, $this->_timeout);
         return true;
     }
     // Connect to the FTP server.
     $this->_conn = @fsockopen($host, $port, $errno, $err, $this->_timeout);
     if (!$this->_conn) {
         JError::raiseWarning('30', JText::sprintf('JLIB_CLIENT_ERROR_JFTP_NO_CONNECT_SOCKET', $host, $port, $errno, $err));
         return false;
     }
     // Set the timeout for this connection
     socket_set_timeout($this->_conn, $this->_timeout);
     // Check for welcome response code
     if (!$this->_verifyResponse(220)) {
         JError::raiseWarning('35', JText::sprintf('JLIB_CLIENT_ERROR_JFTP_BAD_RESPONSE', $this->_response));
         return false;
     }
     return true;
 }
Exemple #21
0
 /** Opens the log file.
  * This function opens the log file. If the log is on an FTP server, it will login, try to get its size, and open the local buffer file. If the size
  * 
  * \return TRUE if log loaded correctly, FALSE otherwise.
  */
 public function openLogFile($resume = FALSE)
 {
     switch ($this->_logfile['type']) {
         case 'file':
             Leelabot::message('Opening local game log file...');
             if (!($this->_logfile['fp'] = fopen($this->_logfile['location'], 'r'))) {
                 Leelabot::message('Can\'t open local log file : $0.', array($this->_logfile['location']), E_WARNING);
                 return FALSE;
             }
             if (!$resume) {
                 fseek($this->_logfile['fp'], 0, SEEK_END);
             }
             break;
         case 'ftp':
             Leelabot::message('Connecting to FTP server...');
             //Connecting to FTP server
             if (strpos($this->_logfile['server'], ':')) {
                 list($address, $port) = explode(':', $this->_logfile['server']);
             } else {
                 list($address, $port) = array($this->_logfile['server'], 21);
             }
             if (!($this->_logfile['ftp'] = ftp_connect($address, $port))) {
                 Leelabot::message('Can\'t connect to the log server.', array(), E_WARNING);
                 return FALSE;
             }
             ftp_set_option($this->_logfile['ftp'], FTP_AUTOSEEK, false);
             //Login
             if (!ftp_login($this->_logfile['ftp'], $this->_logfile['login'], $this->_logfile['password'])) {
                 Leelabot::message('Can\'t log in to the server.', array(), E_WARNING);
                 return FALSE;
             }
             if (!$resume) {
                 //Creating the buffer and getting end of remote log (to avoid entire log download)
                 Leelabot::message('Initializing online log read...');
                 $this->_logfile['fp'] = fopen('php://memory', 'r+');
                 $this->_logfile['state'] = FTP_FINISHED;
                 if (!($this->_logfile['origpointer'] = ftp_size($this->_logfile['ftp'], $this->_logfile['location']))) {
                     //If we can't get the size, we try to download the whole file into another temp file, and check its size
                     Leelabot::message('Can\'t get actual log size. Trying to download whole file (might be slow)...');
                     $tmpfile = fopen('php://memory', 'r+');
                     if (!ftp_get($this->_logfile['ftp'], $tmpfile, $this->_logfile['location'], FTP_BINARY)) {
                         Leelabot::message('Can\'t download log file.', array(), E_WARNING);
                         return FALSE;
                     }
                     $stat = stat($tmpfile);
                     $this->_logfile['origpointer'] = $stat['size'];
                     fclose($tmpfile);
                 }
                 $this->_logfile['pointer'] = 0;
             }
             break;
     }
     return TRUE;
 }
 function login()
 {
     if ($this->destination_info['protocol'] == "sftp") {
         $this->error_array['responseArray'][] = "Using sFTP connection";
         $this->error_array['responseArray'][] = "Connecting to host: " . $this->destination_info['address'] . " Port: " . $this->destination_info['port'] . " Timeout: " . $this->destination_info['timeout'];
         set_include_path(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpseclib0.2.2' . PATH_SEPARATOR . get_include_path());
         require_once 'Net/SFTP.php';
         $this->sftp_connection = new Net_SFTP($this->destination_info['address'], $this->destination_info['port'], $this->destination_info['timeout']);
         if (!$this->sftp_connection->login($this->destination_info['username'], $this->destination_info['password'])) {
             $this->error_array['errorStatus'] = true;
             $this->error_array['responseArray'][] = "Login attempt failed. Check username and password.";
             //echo "sftp errors<pre>"; print_r($$this->sftp_connection); echo "</pre>";
             $this->error_array['errorArray'] = array_merge($this->error_array['errorArray'], $this->sftp_connection->getSFTPErrors());
             return false;
         } else {
             $this->error_array['responseArray'][] = "Login success.";
             $this->error_array['responseArray'][] = "Home/Root: " . $this->get_remote_directory();
             return true;
         }
     } else {
         if ($this->destination_info['protocol'] == "ftp") {
             $this->error_array['responseArray'][] = "Using FTP connection";
             $this->error_array['responseArray'][] = "Connecting to host: " . $this->destination_info['address'] . " Port: " . $this->destination_info['port'] . " Timeout: " . $this->destination_info['timeout'];
             $this->ftp_connection = ftp_connect($this->destination_info['address'], intval($this->destination_info['port']));
         } else {
             if ($this->destination_info['protocol'] == "ftps-tcl-ssl") {
                 $this->error_array['responseArray'][] = "Using FTP with TSL/SSL connection";
                 $this->error_array['responseArray'][] = "Connecting to host: " . $this->destination_info['address'] . " Port: " . $this->destination_info['port'] . " Timeout: " . $this->destination_info['timeout'];
                 $this->ftp_connection = ftp_ssl_connect($this->destination_info['address'], intval($this->destination_info['port']));
             }
         }
         if (!is_resource($this->ftp_connection)) {
             $this->error_array['errorStatus'] = true;
             $this->error_array['responseArray'][] = "ftp_connect failed.";
             $last_error = error_get_last();
             if (isset($last_error['message'])) {
                 $this->error_array['errorArray'][] = $last_error['message'];
             }
             return false;
         }
         $login_result = ftp_login($this->ftp_connection, $this->destination_info['username'], $this->destination_info['password']);
         if (!$login_result) {
             $this->error_array['errorStatus'] = true;
             $this->error_array['responseArray'][] = "ftp_login failed.";
             $last_error = error_get_last();
             if (isset($last_error['message'])) {
                 $this->error_array['errorArray'][] = $last_error['message'];
             }
             return false;
         } else {
             // turn passive mode on/off
             if ($this->destination_info['passive'] == "no") {
                 $this->error_array['responseArray'][] = "Passive mode off.";
                 ftp_pasv($this->ftp_connection, false);
             } else {
                 $this->error_array['responseArray'][] = "Passive mode on.";
                 ftp_pasv($this->ftp_connection, true);
             }
             @ftp_set_option($this->ftp_connection, FTP_TIMEOUT_SEC, $this->destination_info['timeout']);
             $this->error_array['responseArray'][] = "Timeout set to " . $this->destination_info['timeout'];
             $this->error_array['responseArray'][] = "Login success.";
             $this->error_array['responseArray'][] = "Home/Root: " . $this->get_remote_directory();
             return true;
         }
     }
 }
Exemple #23
0
 /**
  * Назначить таймаут
  * 
  * @param int $timeout
  * @return bool
  */
 public function set_timeout($timeout)
 {
     $timeout = (int) $timeout;
     $this->_timeout = $timeout;
     if (!empty($this->_conn_id)) {
         if ($this->_timeout != 30) {
             @ftp_set_option($this->_conn_id, FTP_TIMEOUT_SEC, $this->_timeout);
         }
     }
     return true;
 }
Exemple #24
0
 /**
  *
  * 设置各种 FTP 运行时选项
  *
  * @param int $option
  * @param mixed $value
  * @return bool
  */
 public static function setOption($option, $value)
 {
     return ftp_set_option(self::$resource, $option, $value);
 }
Exemple #25
0
 /**
  * Set the command timeout period in seconds
  * 
  * @param int $timeout The timeout period
  * @return $this
  */
 public function setTimeout($timeout)
 {
     $this->_timeout = $timeout;
     if ($this->_connection !== null) {
         $option = @ftp_set_option($this->_connection, FTP_TIMEOUT_SEC, $this->_timeout);
         if ($option === false) {
             throw new Centurion_Ftp_Exception('Unable to set timeout');
         }
     }
     return $this;
 }
Exemple #26
0
 /**
  * Set the connections to passive mode.
  *
  * @throws RuntimeException
  */
 protected function setConnectionPassiveMode()
 {
     if (is_bool($this->ignorePassiveAddress) && defined('FTP_USEPASVADDRESS')) {
         ftp_set_option($this->connection, FTP_USEPASVADDRESS, !$this->ignorePassiveAddress);
     }
     if (!ftp_pasv($this->connection, $this->passive)) {
         throw new RuntimeException('Could not set passive mode for connection: ' . $this->getHost() . '::' . $this->getPort());
     }
 }
Exemple #27
0
 public function set_option($cmd, $value)
 {
     if (function_exists('ftp_set_option')) {
         return @ftp_set_option($this->conn_id, $cmd, $value);
     }
 }
Exemple #28
0
 /**
  * Method to connect to a FTP server
  *
  * @access public
  * @param string $host Host to connect to [Default: 127.0.0.1]
  * @param string $port Port to connect on [Default: port 21]
  * @return boolean True if successful
  */
 function connect($host = '127.0.0.1', $port = 21)
 {
     // Initialise variables.
     $errno = null;
     $err = null;
     // If already connected, return
     if (is_resource($this->_conn)) {
         return true;
     }
     // If native FTP support is enabled lets use it...
     if (FTP_NATIVE) {
         $this->_conn = @ftp_connect($host, $port, $this->_timeout);
         if ($this->_conn === false) {
             JError::raiseWarning('30', 'JFTP::connect: Could not connect to host "' . $host . '" on port ' . $port);
             return false;
         }
         // Set the timeout for this connection
         ftp_set_option($this->_conn, FTP_TIMEOUT_SEC, $this->_timeout);
         return true;
     }
     // Connect to the FTP server.
     $this->_conn = @fsockopen($host, $port, $errno, $err, $this->_timeout);
     if (!$this->_conn) {
         JError::raiseWarning('30', 'JFTP::connect: Could not connect to host "' . $host . '" on port ' . $port, 'Socket error number ' . $errno . ' and error message: ' . $err);
         return false;
     }
     // Set the timeout for this connection
     socket_set_timeout($this->_conn, $this->_timeout);
     // Check for welcome response code
     if (!$this->_verifyResponse(220)) {
         JError::raiseWarning('35', 'JFTP::connect: Bad response', 'Server response: ' . $this->_response . ' [Expected: 220]');
         return false;
     }
     return true;
 }
Exemple #29
0
 public function connect()
 {
     // Implicit SSL - not handled via PHP's native ftp_ functions, so we use curl instead
     if ($this->port == 990 || defined('UPDRAFTPLUS_FTP_USECURL') && UPDRAFTPLUS_FTP_USECURL) {
         if ($this->ssl == false) {
             $this->port = 21;
         } else {
             $this->curl_handle = curl_init();
             if (!$this->curl_handle) {
                 $this->port = 21;
             } else {
                 $options = array(CURLOPT_USERPWD => $this->username . ':' . $this->password, CURLOPT_PORT => $this->port, CURLOPT_CONNECTTIMEOUT => 20, CURLOPT_FTP_CREATE_MISSING_DIRS => true);
                 $options[CURLOPT_FTP_SSL] = CURLFTPSSL_TRY;
                 //CURLFTPSSL_ALL, // require SSL For both control and data connections
                 if (990 == $this->port) {
                     $options[CURLOPT_FTPSSLAUTH] = CURLFTPAUTH_SSL;
                     // CURLFTPAUTH_DEFAULT, // let cURL choose the FTP authentication method (either SSL or TLS)
                 } else {
                     $options[CURLOPT_FTPSSLAUTH] = CURLFTPAUTH_DEFAULT;
                     // let cURL choose the FTP authentication method (either SSL or TLS)
                 }
                 // Prints to STDERR by default - noisy
                 if (defined('WP_DEBUG') && WP_DEBUG == true && UpdraftPlus_Options::get_updraft_option('updraft_debug_mode')) {
                     $options[CURLOPT_VERBOSE] = true;
                 }
                 if ($this->disable_verify) {
                     $options[CURLOPT_SSL_VERIFYPEER] = false;
                     $options[CURLOPT_SSL_VERIFYHOST] = 0;
                 } else {
                     $options[CURLOPT_SSL_VERIFYPEER] = true;
                 }
                 if (!$this->use_server_certs) {
                     $options[CURLOPT_CAINFO] = UPDRAFTPLUS_DIR . '/includes/cacert.pem';
                 }
                 if ($this->passive != true) {
                     $options[CURLOPT_FTPPORT] = '-';
                 }
                 foreach ($options as $option_name => $option_value) {
                     if (!curl_setopt($this->curl_handle, $option_name, $option_value)) {
                         // 							throw new Exception( sprintf( 'Could not set cURL option: %s', $option_name ) );
                         global $updraftplus;
                         if (is_a($updraftplus, 'UpdraftPlus')) {
                             $updraftplus->log("Curl exception: will revert to normal FTP");
                         }
                         $this->port = 21;
                         $this->curl_handle = false;
                     }
                 }
             }
             // All done - leave
             if ($this->curl_handle) {
                 $this->login_type = 'encrypted (implicit, port 990)';
                 return true;
             }
         }
     }
     $time_start = time();
     if (function_exists('ftp_ssl_connect') && $this->ssl !== false) {
         $this->conn_id = ftp_ssl_connect($this->host, $this->port, 15);
         $attempting_ssl = true;
     }
     if ($this->conn_id) {
         $this->login_type = 'encrypted';
         $this->ssl = true;
     } else {
         $this->conn_id = ftp_connect($this->host, $this->port, 15);
     }
     if ($this->conn_id) {
         $result = ftp_login($this->conn_id, $this->username, $this->password);
     }
     if (!empty($result)) {
         ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $this->timeout);
         ftp_pasv($this->conn_id, $this->passive);
         $this->system_type = ftp_systype($this->conn_id);
         return true;
     } elseif (!empty($attempting_ssl)) {
         global $updraftplus_admin;
         if (isset($updraftplus_admin->logged) && is_array($updraftplus_admin->logged)) {
             # Clear the previous PHP messages, so that we only show the user messages from the method that worked (or from both if both fail)
             $save_array = $updraftplus_admin->logged;
             $updraftplus_admin->logged = array();
             #trigger_error(__('Encrypted login failed; trying non-encrypted', 'updraftplus'), E_USER_NOTICE);
         }
         $this->ssl = false;
         $this->login_type = 'non-encrypted';
         $time_start = time();
         $this->conn_id = ftp_connect($this->host, $this->port, 15);
         if ($this->conn_id) {
             $result = ftp_login($this->conn_id, $this->username, $this->password);
         }
         if (!empty($result)) {
             ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $this->timeout);
             ftp_pasv($this->conn_id, $this->passive);
             $this->system_type = ftp_systype($this->conn_id);
             return true;
         } else {
             # Add back the previous PHP messages
             if (isset($save_array)) {
                 $updraftplus_admin->logged = array_merge($save_array, $updraftplus_admin->logged);
             }
         }
     }
     # If we got here, then we failed
     if (time() - $time_start > 14) {
         global $updraftplus_admin;
         if (isset($updraftplus_admin->logged) && is_array($updraftplus_admin->logged)) {
             $updraftplus_admin->logged[] = sprintf(__('The %s connection timed out; if you entered the server correctly, then this is usually caused by a firewall blocking the connection - you should check with your web hosting company.', 'updraftplus'), 'FTP');
         } else {
             global $updraftplus;
             $updraftplus->log(sprintf(__('The %s connection timed out; if you entered the server correctly, then this is usually caused by a firewall blocking the connection - you should check with your web hosting company.', 'updraftplus'), 'FTP'), 'error');
         }
     }
     return false;
 }
Exemple #30
-5
 /**
  * 下载文件
  * 
  */
 public function download($localfile, $remotefile)
 {
     ftp_set_option($this->ftpobj, FTP_AUTOSEEK, FALSE);
     $res = ftp_nb_get($this->ftpobj, $localfile, $remotefile, $this->mode, ftp_size($this->ftpobj, $localfile));
     while ($res == FTP_MOREDATA) {
         $res = ftp_nb_continue($this->ftpobj);
     }
     if ($res != FTP_FINISHED) {
         return FALSE;
     }
     return TRUE;
 }