/** * Connect to FTP server and authenticate via password * * @since 3.0 * @throws Exception * @return \WC_Customer_Order_CSV_Export_Method_FTP */ public function __construct() { parent::__construct(); // Handle errors from ftp_* functions that throw warnings for things like invalid username / password, failed directory changes, and failed data connections set_error_handler(array($this, 'handle_errors')); // setup connection $this->link = null; if ('ftps' == $this->security && function_exists('ftp_ssl_connect')) { $this->link = ftp_ssl_connect($this->server, $this->port, $this->timeout); } elseif ('ftps' !== $this->security) { $this->link = ftp_connect($this->server, $this->port, $this->timeout); } // check for successful connection if (!$this->link) { throw new Exception(__("Could not connect via FTP to {$this->server} on port {$this->port}, check server address and port.", WC_Customer_Order_CSV_Export::TEXT_DOMAIN)); } // attempt to login, note that incorrect credentials throws an E_WARNING PHP error if (!ftp_login($this->link, $this->username, $this->password)) { throw new Exception(__("Could not authenticate via FTP with username {$this->username} and password <hidden>. Check username and password.", WC_Customer_Order_CSV_Export::TEXT_DOMAIN)); } // set passive mode if enabled if ($this->passive_mode) { // check for success if (!ftp_pasv($this->link, true)) { throw new Exception(__('Could not set passive mode', WC_Customer_Order_CSV_Export::TEXT_DOMAIN)); } } // change directories if initial path is populated, note that failing to change directory throws an E_WARNING PHP error if ($this->path) { // check for success if (!ftp_chdir($this->link, '/' . $this->path)) { throw new Exception(__("Could not change directory to {$this->path} - check path exists.", WC_Customer_Order_CSV_Export::TEXT_DOMAIN)); } } }
/** * Tries to logon to the FTP server with given id and password * * @access public * * @param string $source Authentication source to be used * @param string $external_uid The ID entered * @param string $external_passwd The password of the user * * @return boolean True if the authentication was a success, false * otherwise */ public function Authenticate($source, $external_uid, $external_passwd) { $enc = ExternalAuthenticator::getAuthEnc($source); $port = ExternalAuthenticator::getAuthPort($source); if (is_null($port)) { $port = self::$port; } ExternalAuthenticator::AuthLog($external_uid . '.ftp - Connecting to ' . ExternalAuthenticator::getAuthServer($source) . ' port ' . $port); if ($enc == 'ssl') { ExternalAuthenticator::AuthLog($external_uid . '.ftp - Connection type is SSL'); $conn = @ftp_ssl_connect(ExternalAuthenticator::getAuthServer($source), $port); } else { $conn = @ftp_connect(ExternalAuthenticator::getAuthServer($source), $port); } if (!$conn) { ExternalAuthenticator::AuthLog($external_uid . '.ftp - Connection to server failed'); ExternalAuthenticator::setAuthMessage(_t('FTP_Authenticator.NoConnect', 'Could not connect to FTP server')); return false; } else { ExternalAuthenticator::AuthLog($external_uid . '.ftp - Connection to server succeeded'); } if (!@ftp_login($conn, $external_uid, $external_passwd)) { ExternalAuthenticator::AuthLog($external_uid . '.ftp - User credentials failed at ftp server'); ftp_close($conn); ExternalAuthenticator::setAuthMessage(_t('ExternalAuthenticator.Failed')); return false; } else { ExternalAuthenticator::AuthLog($external_uid . '.ftp - ftp server validated credentials'); ftp_close($conn); return true; } }
function test_connection() { if ($this->input->is_ajax_request()) { header('Content-Type: application/json', true); $ftp_server = trim($this->input->post('address')); $ftp_user = trim($this->input->post('user')); $ftp_password = trim($this->input->post('password')); $port = trim($this->input->post('port')); // set up basic connection if ($this->input->post('SFTP') == true) { $conn_id = @ftp_ssl_connect($ftp_server, $port) or die(json_encode(array('status' => 'error', 'output' => '<span class="delete ftp-alert cmsicon" style="display: inline-block;float: none;"></span> Couldn\'t connect to ' . $ftp_server))); } else { $conn_id = @ftp_connect($ftp_server, $port) or die(json_encode(array('status' => 'error', 'output' => '<span class="delete ftp-alert cmsicon" style="display: inline-block;float: none;"></span> Couldn\'t connect to ' . $ftp_server))); } // login with username and password if (!@ftp_login($conn_id, $ftp_user, $ftp_password)) { $output = array('status' => 'error', 'output' => '<span class="cus-cross-octagon"></span> Username and Password is incorrect'); } else { $output = array('status' => 'success', 'output' => '<span class="cus-accept"></span> Connection OK!'); } ftp_close($conn_id); echo json_encode($output); } else { show_404(); } }
/** * Connect to FTP Server. Use ssl + passive mode by default. * * @throws * @see __construct * @param string $host * @param string $user * @param string $pass */ public function open($host, $user, $pass) { $this->setConf(['host' => $host, 'login' => $user, 'password' => $pass]); $required = ['host', 'login', 'password', 'port', 'timeout']; foreach ($required as $key) { if (empty($this->conf[$key])) { throw new Exception('empty conf parameter', $key); } } if ($this->conf['ssl']) { $this->ftp = @ftp_ssl_connect($this->conf['host'], $this->conf['port'], $this->conf['timeout']); } else { $this->ftp = @ftp_connect($this->conf['host'], $this->conf['port'], $this->conf['timeout']); } if ($this->ftp === false) { throw new Exception('FTP connect failed', 'host=' . $this->conf['host'] . ' port=' . $this->conf['port']); } if (!@ftp_login($this->ftp, $this->conf['login'], $this->conf['password'])) { $ssl_msg = $this->conf['ssl'] ? ' - try without ssl' : ' - try with ssl'; throw new Exception('FTP login failed' . $ssl_msg, 'login='******'login'] . ' password='******'password'], 0, 2) . '***'); } if ($this->conf['passive'] && !@ftp_pasv($this->ftp, true)) { throw new Exception('Failed to switch to passive FTP mode'); } $this->_log('FTP connected to ' . $this->conf['host']); }
/** * connect to the server. */ public function connect() { if ($this->connection !== null) { return; } if ($this->config->getSSL()) { $this->connection = ftp_ssl_connect($this->config->getHost(), $this->config->getPort(), $this->config->getTimeout()); } else { $this->connection = ftp_connect($this->config->getHost(), $this->config->getPort(), $this->config->getTimeout()); } if ($this->connection === false) { throw new FTPFilesystemConnectionException('Could not connect to ' . $this->config->getHost()); } if ($this->config->getUsername()) { if (!ftp_login($this->connection, $this->config->getUsername(), $this->config->getPassword())) { throw new FTPFilesystemAuthenticationException('Could not login to ' . $this->config->getHost() . ' with username ' . $this->config->getUsername() . ':' . ($this->config->getPassword() ? '*****' : 'NOPASS')); } } ftp_pasv($this->connection, $this->config->getPassiveMode()); if ($this->config->getBasePath()) { if (!ftp_chdir($this->connection, $this->config->getBasePath())) { throw new FTPFilesystemException('Could not change into directory ' . $this->config->getBasePath() . ' on ' . $this->config->getHost()); } } }
/** * FTP Connect * * @access public * @param array the connection values * @return bool */ function connect($config = array()) { if ($this->_is_conn() == TRUE) { return TRUE; } if (count($config) > 0) { $this->initialize($config); } if ($this->ssl == TRUE) { if (function_exists('ftp_ssl_connect')) { $this->conn_id = @ftp_ssl_connect($this->hostname, $this->port, $this->timeout); } else { $this->_error('ftp_ssl_not_supported'); return FALSE; } } else { $this->conn_id = @ftp_connect($this->hostname, $this->port, $this->timeout); } if ($this->conn_id === FALSE) { $this->_error('ftp_unable_to_connect'); return FALSE; } if (!$this->_login()) { $this->_error('ftp_unable_to_login'); return FALSE; } // Set passive mode if needed if ($this->passive == TRUE) { ftp_pasv($this->conn_id, TRUE); } return TRUE; }
function connect() { if (!$this->options['hostname'] || !$this->options['username'] || !$this->options['password']) { if (!defined('SUPPORT_URL')) { define('SUPPORT_URL', getOption('supportURL')); } appUpdateMsg('<a href="' . SUPPORT_URL . 'solution/articles/195233-asking-for-ftp-sftp-details-during-update/" target="_blank">See how to add the FTP details</a>.'); return false; } 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'])); appUpdateMsg(sprintf('Failed to connect to the 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'])); appUpdateMsg(sprintf('FTP username or password incorrect for "%s"', $this->options['username'])); return false; } //Set the Connection to use Passive FTP if ($this->options['passive']) { @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; }
/** * FTP Connect * * @access public * @param array the connection values * @return bool */ public function connect() { if ($this->_ssl === true) { if (!function_exists('ftp_ssl_connect')) { throw new \RuntimeException('ftp_ssl_connect() function is missing.'); } $this->_conn = @ftp_ssl_connect($this->_hostname, $this->_port, $this->_timeout); } else { $this->_conn = @ftp_connect($this->_hostname, $this->_port, $this->_timeout); } if ($this->_conn === false) { if ($this->_debug == true) { throw new \Exception('FTP - Unable to establish a connection'); } return false; } if (!$this->_login()) { if ($this->_debug == true) { throw new \Exception('FTP - Unable to login'); } } // Set passive mode if needed if ($this->_passive == true) { ftp_pasv($this->_conn, true); } return $this; }
/** * 连接FTP服务器 * @param string $host 服务器地址 * @param string $username 用户名 * @param string $password 密码 * @param integer $port 服务器端口,默认值为21 * @param boolean $pasv 是否开启被动模式 * @param boolean $ssl 是否使用SSL连接 * @param integer $timeout 超时时间 */ public function connect($host, $username = '', $password = '', $port = '21', $pasv = false, $ssl = false, $timeout = 30) { $start = time(); if ($ssl) { if (!($this->link = @ftp_ssl_connect($host, $port, $timeout))) { $this->err_code = 1; return false; } } else { if (!($this->link = ftp_connect($host, $port, $timeout))) { $this->err_code = 1; return false; } } if (ftp_login($this->link, $username, $password)) { if ($pasv) { ftp_pasv($this->link, true); } $this->link_time = time() - $start; return true; } else { $this->err_code = 1; return false; } register_shutdown_function(array(&$this, 'close')); }
function connect($ssl = false) { if (!is_bool($ssl)) { $ssl = false; } $this->ssl = $ssl; if (!$this->ssl) { if (!($this->_connectid = ftp_connect($this->_host, $this->_port, $this->_timeout))) { $this->error[] = "Błąd połączenia z serwerem FTP " . $this->_host; return false; } } elseif (function_exists("ftp_ssl_connect")) { if (!($this->_connectid = ftp_ssl_connect($this->_host, $this->_port, $this->_timeout))) { $this->error = "Błąd połączenia z serwerem FTP " . $this->_host . " (SSL)"; return false; } } else { $this->error = "Błąd połączenia z serwerem FTP " . $this->_host . " (nieznany typ połączenia)"; return false; } if (ftp_login($this->_connectid, $this->_user, $this->_pass)) { ftp_pasv($this->_connectid, (bool) $this->passive); $this->system_type = ftp_systype($this->_connectid); return true; } else { $this->error = "Błąd połączenia z serwerem FTP " . $this->_host . " - błędny login"; return false; } }
/** * Connect to an FTP server. * * @return Object FTP connection */ private static function _connect() { // do we have an instance already? if (!isset(self::$instance)) { // give us an ftp connection // try ssl first @($connection = ftp_ssl_connect(FTP_HOST)); if (!$connection) { // go old school @($connection = ftp_connect(FTP_HOST)); // fail if we don't have a connection if (!$connection) { return array('status' => 'fail', 'message' => 'Couldn\'t connect to the FTP server.'); } } // login to the server @($login = ftp_login($connection, FTP_USER, FTP_PASS)); // check that login went fine if (!$login) { return array('status' => 'fail', 'message' => 'Incorrect FTP account credentials.'); } // change connection to a passive mode (connection initiated by client and not server) ftp_pasv($connection, TRUE); // set ftp connection self::$instance = $connection; } return self::$instance; }
public function __construct($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false) { $host = mb_substr($host, -1, 1) == '/' ? mb_substr($host, 0, mb_strlen($host) - 1) : $host; if (mb_strpos($host, 'ftp://') !== false) { $host = mb_substr($host, 6); } $host = $proxy ? $proxy : $host; $port = $proxyport ? $proxyport : $port; if ($this->debug && $proxy) { echo "Utilisation du proxy {$proxy}\n<br>"; } if ($this->debug && $proxyport) { echo "Utilisation du port proxy {$proxyport}\n<br>"; } $this->proxy = $proxy; $this->host = $host; if ($this->debug) { echo "Ouverture de connection vers {$host}:{$port} timeout {$timeout} et proxy {$proxy}:{$proxyport}\n<br>"; } if (trim($host) == '') { throw new Exception('Nom d\'hote incorrect ' . $host); } if ($ssl === true) { if (($this->connexion = @ftp_ssl_connect($host, $port, $timeout)) === false) { throw new Exception('Impossible de se connecter au serveur FTP en SSL'); } } else { if (($this->connexion = @ftp_connect($host, $port, $timeout)) === false) { throw new Exception('Impossible de se connecter au serveur FTP ' . $host . ":{$port} {$timeout}"); } } return $this; }
/** * @param mixed string or URL object * @param int Connection timeout in seconds * @throws IOException * @throws IllegalArgumentException */ public function __construct($url, $timeout = 30) { $url = URL::valueOf($url); try { if ($url->isProtocol('ftp')) { $this->conn = ftp_connect($url->getHost('localhost'), $url->getPort(), $timeout); } elseif ($url->isProtocol('ftps')) { $this->conn = ftp_ssl_connect($url->getHost('localhost'), $url->getPort(), $timeout); } else { throw new IllegalTypeException('Unsupported protocol: ' . $url->getProtocol('???')); } } catch (PHPException $e) { $e->setMessage(str_replace(array('ftp_connect(): ', 'ftp_ssl_connect(): '), '', $e->getMessage())); throw new ConnectException($e); } if ($this->conn == false) { throw new ConnectException('Failed to connect (unknown reason)'); } if ($url->getUser()) { $this->login($url->getUser(), $url->getPassword('')); } if ($url->getPath()) { $this->cd($url->getPath()); } }
/** * * @param string $host * @param string $user * @param string $pass * @param string $port * @param boolean $passive * @param boolean $ssl * @return boolean * @throws Exception */ public function connect($host, $user, $pass, $port = 21, $passive = true, $ssl = false) { $this->host = $host; $this->user = $user; $this->pass = $pass; $this->port = $port; $this->_idFtp = null; $this->passive = $passive; $this->ssl = $ssl; if ($this->ssl) { $this->_idFtp = @ftp_ssl_connect($this->host, $this->port); } else { $this->_idFtp = @ftp_connect($this->host, $this->port); } if (!$this->_idFtp) { throw new Exception('Nao foi possivel conectar ao servidor "' . $this->host . '" sobre a porta "' . $this->port . '".', -32001); } $result = @ftp_login($this->_idFtp, $this->user, $this->pass); if (!$result) { throw new Exception('Usuario ou senha invalido!', -32010); } if (!@ftp_pasv($this->_idFtp, $this->passive)) { throw new Exception('Nao foi possivel alterar o modo "passive mode"!', -32002); } $this->_isConnected = true; return true; }
public function getListing() { $dir = $this->directory; // Parse directory to parts $parsed_dir = trim($dir, '/'); $this->parts = empty($parsed_dir) ? array() : explode('/', $parsed_dir); // Find the path to the parent directory if (!empty($parts)) { $copy_of_parts = $parts; array_pop($copy_of_parts); if (!empty($copy_of_parts)) { $this->parent_directory = '/' . implode('/', $copy_of_parts); } else { $this->parent_directory = '/'; } } else { $this->parent_directory = ''; } // Connect to the server if ($this->ssl) { $con = @ftp_ssl_connect($this->host, $this->port); } else { $con = @ftp_connect($this->host, $this->port); } if ($con === false) { $this->setError(JText::_('FTPBROWSER_ERROR_HOSTNAME')); return false; } // Login $result = @ftp_login($con, $this->username, $this->password); if ($result === false) { $this->setError(JText::_('FTPBROWSER_ERROR_USERPASS')); return false; } // Set the passive mode -- don't care if it fails, though! @ftp_pasv($con, $this->passive); // Try to chdir to the specified directory if (!empty($dir)) { $result = @ftp_chdir($con, $dir); if ($result === false) { $this->setError(JText::_('FTPBROWSER_ERROR_NOACCESS')); return false; } } else { $this->directory = @ftp_pwd($con); $parsed_dir = trim($this->directory, '/'); $this->parts = empty($parsed_dir) ? array() : explode('/', $parsed_dir); $this->parent_directory = $this->directory; } // Get a raw directory listing (hoping it's a UNIX server!) $list = @ftp_rawlist($con, '.'); ftp_close($con); if ($list === false) { $this->setError(JText::_('FTPBROWSER_ERROR_UNSUPPORTED')); return false; } // Parse the raw listing into an array $folders = $this->parse_rawlist($list); return $folders; }
/** * 建立ssl ftp连接 * */ protected function connectSsl() { $ftpobj = @ftp_ssl_connect($this->host, $this->port, $this->timeout); if (null == $ftpobj) { throw new FtpException("FTP ERROR : Couldn't connect to {$this->host}"); } }
public function sslConnect() { try { $this->resource = ftp_ssl_connect($this->host, $this->port); } catch (Exception $e) { throw new Exception("Unable to establish a SSL-FTP connection to host: " . $this->host . ':' . $this->port); } $this->login(); }
/** * @desc Coneción al servidor * @return bool */ public function connect($ssl = false, $timeout = 90) { $this->connection = $ssl ? ftp_ssl_connect($this->server, $this->port, $timeout) : ftp_connect($this->server, $this->port, $timeout); if (!ftp_login($this->connection, $this->uname, $this->pass)) { return false; } else { return true; } }
/** * Establish a connection * @todo Options... */ public function __construct($url, array $options = null) { $data = parse_url($url); //Establish connection to the server if (isset($data['scheme']) && strtolower($data['scheme']) == 'ftps') { if (isset($data['port']) && $data['port']) { $this->conn = ftp_ssl_connect($data['host'], $data['port']); if (!$this->conn) { throw new \Exception("Could not connect to 'ftps://{$data['host']}:{$data['port']}'"); } } else { $this->conn = ftp_ssl_connect($data['host']); if (!$this->conn) { throw new \Exception("Could not connect to 'ftps://{$data['host']}'"); } } } else { if (isset($data['port']) && $data['port']) { $this->conn = ftp_connect($data['host'], $data['port']); if (!$this->conn) { throw new \Exception("Could not connect to 'ftp://{$data['host']}:{$data['port']}'"); } } else { $this->conn = ftp_connect($data['host']); if (!$this->conn) { throw new \Exception("Could not connect to 'ftp://{$data['host']}'"); } } } //Provide username and password if (isset($data['user'])) { $user = $data['user']; } else { $user = '******'; } if (isset($data['pass'])) { $pass = $data['pass']; } else { $pass = ''; } if (!ftp_login($this->conn, $user, $pass)) { throw new \Exception("Could not login to '{$data['host']}' as '{$user}'"); } //Use firewall friendly passive mode if (!ftp_pasv($this->conn, true)) { trigger_error("Passive mode failed", \E_USER_WARNING); } //Go to defined directory if (isset($data['path']) && $data['path']) { // Make sure the $path ends with a slash. $data['path'] = rtrim($data['path'], '/') . '/'; if (!$this->cd(urldecode($data['path']))) { throw new \Exception("Could not change directory to '{$data['path']}'. Please make sure the directory exists."); } } }
public function createSecondFTPConnect($ip, $port, $user, $pwd, $ssl = 'N') { $this->ftpSecondConnection = $ssl == 'N' ? @ftp_connect($ip, $port, 5) : @ftp_ssl_connect($ip, $port, 5); if ($this->ftpSecondConnection) { $ftpLogin = @ftp_login($this->ftpSecondConnection, $user, $pwd); if ($ftpLogin) { $this->secondLoggedIn = true; return true; } } return false; }
function connect($base_dir = null) { static $ftp_conn, $_base_dir, $disconnected = false; if (!isset($ftp_conn) || $disconnected) { if (!defined('AK_FTP_PATH')) { trigger_error(Ak::t('You must set a valid FTP connection on AK_FTP_PATH in your config/config.php file'), E_USER_ERROR); } else { if (AK_AUTOMATIC_CONFIG_VARS_ENCRYPTION && substr(AK_FTP_PATH, 0, 10) == 'PROTECTED:') { // You should change the key bellow and encode this file if you are going to distribute applications // The ideal protection would be to encode user configuration file. $AK_FTP_PATH = Ak::decrypt(base64_decode(substr(AK_FTP_PATH, 10)), 'HR23JHR93JZ0ALi1UvTZ0ALi1UvTk7MD70'); $_pass_encoded = true; } else { $AK_FTP_PATH = AK_FTP_PATH; } $f = parse_url($AK_FTP_PATH); if (@$f['scheme'] != 'ftps') { $ftp_conn = isset($f['port']) ? ftp_connect($f['host'], $f['port']) : ftp_connect($f['host']); } else { $ftp_conn = isset($f['port']) ? ftp_ssl_connect($f['host'], $f['port']) : ftp_ssl_connect($f['host']); } $f['user'] = str_replace('+', '@', @$f['user']); $login_result = ftp_login($ftp_conn, $f['user'], @$f['pass']); if (!$ftp_conn || !$login_result) { AK_FTP_SHOW_ERRORS ? trigger_error(Ak::t('Could not connect to the FTP server'), E_USER_NOTICE) : null; return false; } $_base_dir = isset($f['path']) ? '/' . trim($f['path'], '/') : '/'; if (defined('AK_FTP_AUTO_DISCONNECT') && AK_FTP_AUTO_DISCONNECT) { register_shutdown_function(array('AkFtp', 'disconnect')); } if (AK_AUTOMATIC_CONFIG_VARS_ENCRYPTION && empty($_pass_encoded)) { @register_shutdown_function(create_function('', "@Ak::file_put_contents(AK_CONFIG_DIR.DS.'config.php',\n str_replace(AK_FTP_PATH,'PROTECTED:'.base64_encode(Ak::encrypt(AK_FTP_PATH,'HR23JHR93JZ0ALi1UvTZ0ALi1UvTk7MD70')),\n Ak::file_get_contents(AK_CONFIG_DIR.DS.'config.php')));")); } } } if (isset($base_dir) && $base_dir === 'AK_DISCONNECT_FTP') { $disconnected = true; $base_dir = null; } else { $disconnected = false; } if (!isset($base_dir) && isset($_base_dir) && '/' . trim(ftp_pwd($ftp_conn), '/') != $_base_dir) { if (!@ftp_chdir($ftp_conn, $_base_dir) && AK_FTP_SHOW_ERRORS) { trigger_error(Ak::t('Could not change to the FTP base directory %directory', array('%directory' => $_base_dir)), E_USER_NOTICE); } } elseif (isset($base_dir)) { if (!ftp_chdir($ftp_conn, $base_dir) && AK_FTP_SHOW_ERRORS) { trigger_error(Ak::t('Could not change to the FTP directory %directory', array('%directory' => $base_dir)), E_USER_NOTICE); } } return $ftp_conn; }
function ssl_connect() { // FTPサーバーへ接続 $this->connect_id = ftp_ssl_connect($this->ftp_server); if ($this->connect_id) { // FTPサーバーへログイン $login_result = ftp_login($this->connect_id, $this->user_name, $this->user_pass); if ($login_result) { return true; } } return false; }
/** * Opens a FTP connection * * @param string $host * @param bool $ssl * @param int $port * @param int $timeout * * @return FTPClient */ public function connect($host, $ssl = false, $port = 21, $timeout = 90) { if ($ssl) { $this->connection = @ftp_ssl_connect($host, $port, $timeout); } else { $this->connection = @ftp_connect($host, $port, $timeout); } if ($this->connection == null) { throw new Exception('Unable to connect'); } else { return $this; } }
/** * Connect to the FTP server. */ public function connect() { if ($this->ssl) { $this->connection = ftp_ssl_connect($this->getHost(), $this->getPort(), $this->getTimeout()); } else { $this->connection = ftp_connect($this->getHost(), $this->getPort(), $this->getTimeout()); } if (!$this->connection) { throw new RuntimeException('Could not connect to host: ' . $this->getHost() . ', port:' . $this->getPort()); } $this->login(); $this->setConnectionPassiveMode(); $this->setConnectionRoot(); }
/** * Connects to the FTP server * @return null * @throws zibo\library\ftp\exception\FtpException when no connection could be made */ public function connect() { if ($this->ssl) { $this->handle = @ftp_ssl_connect($this->host, $this->port); } else { $this->handle = @ftp_connect($this->host, $this->port); } if (!$this->handle) { throw new FtpException('Could not connect to ' . $this->host); } if (!@ftp_login($this->handle, $this->username, $this->password)) { throw new FtpException('Could not authenticate with ' . $this->host); } }
/** * Permet de ce connecter au serveur FTP. * * @param string $hostname Le nom de serveur FTP * @param string $username Le nom d'utilisateur * @param string $password Le mot de passe de l'utilisteur. * @param int $port Le port de connection * @param bool $tls Si a true permet d'établir un connection sécuriré. * @param int $timeout Le temps d'attente avant réponse * * @throws \ErrorException */ public function connect($hostname, $username, $password, $port = 21, $tls = false, $timeout = 90) { if ($tls === true) { $this->ftp = ftp_ssl_connect($hostname, $port, $timeout); } else { $this->ftp = ftp_connect($hostname, $port, $timeout); } if ($this->ftp === null) { throw new \ErrorException('Impossible de ce connecté au serveur FTP.'); } if (!ftp_login($this->ftp, $username, $password)) { throw new \ErrorException('Détaille de connection incorrecte.'); } }
/** * Connect to the FTP server. * Also sends login information, detects target FTP OS and sets Passive Mode to TRUE * * @param array $config Login information to connect at the FTP server * @param bool $useSSL Establish a secure SSL-FTP connection * @param bool $fallback If a SSL-FTP connect fails, try a default FTP connect as fallback * @return void */ public function connect($config, $useSSL = false, $fallback = false) { // Check if native FTP support is enabled if (function_exists('ftp_connect') === false) { throw new FTPException(FTPException::FTP_SUPPORT_ERROR); } // Default connection if ($useSSL === false) { if (($this->cid = @ftp_connect($config['host'], $config['port'])) === false) { throw new FTPException(FTPException::CONNECT_FAILED_BADHOST); } } // SSL-FTP connection if ($useSSL === true) { if (!function_exists('ftp_ssl_connect') || !($this->cid = @ftp_ssl_connect($config['host'], $config['port']))) { if ($fallback === false) { throw new FTPException(FTPException::CONNECT_FAILED_NOSSL); } else { if ($fallback === true) { if (!($this->cid = @ftp_connect($config['host'], $config['port']))) { throw new FTPException(FTPException::CONNECT_FAILED_BADHOST); } } } } } // Send login information if (@ftp_login($this->cid, $config['username'], $config['password']) === false) { throw new FTPException(FTPException::CONNECT_FAILED_BADLOGIN); } // Detect FTP Server OS // This is required by some operations, such as chmod, to prevent wrong return values $tmpOS = strtoupper(self::getSystem()); if (strpos($tmpOS, 'MAC') !== false) { $this->serverOS = 'MAC'; } else { if (strpos($tmpOS, 'WIN') !== false) { $this->serverOS = 'WIN'; } else { if (strpos($tmpOS, 'UNIX') !== false) { $this->serverOS = 'UNIX'; } else { throw new FTPException(FTPException::CONNECT_UNKNOWN_OS); } } } // Set Passive mode self::setPassiveMode(true); }
protected static function conn_new($urlData) { $conn = ftp_ssl_connect($urlData['host'], $urlData['port']); if ($conn === false) { return false; } if (!empty($urlData['user'])) { if (!ftp_login($conn, $urlData['user'], $urlData['pass'])) { return false; } } // Turn passive mode on ftp_pasv($conn, true); return $conn; }
function dftp($ftphost, $ftpuser, $ftppass, $ftpport = 21, $root = '/', $pasv = 0, $ssl = 0) { if ($ssl && function_exists('ftp_ssl_connect')) { $this->fp = @ftp_ssl_connect($ftphost, $ftpport); } else { if (function_exists('ftp_connect')) { $this->fp = @ftp_connect($ftphost, $ftpport); } else { return false; } } $this->connected = @ftp_login($this->fp, $ftpuser, $ftppass); @ftp_pasv($this->fp, $pasv); $this->root = dir_path($root); }
public function __construct($host, $port = 21, $timeout = 90, $ssl = false, $proxyhost = false, $proxyport = false, $proxyuser = false, $proxypwd = false) { $this->host = $host; $this->port = $port; $this->proxyhost = $proxyhost; $this->proxyport = $proxyport; $this->proxyuser = $proxyuser; $this->proxypwd = $proxypwd; // if there is a proxy, connect to it, not on host/port provided $host = $proxyhost ? $proxyhost : $host; $port = $proxyport ? $proxyport : $port; // clean the addr, force ssl if needed $host = $this->cleanAddr($host, $ssl); if ($this->debug) { echo "Ouverture de connection vers {$host}:{$port} timeout {$timeout}\n<br>"; } try { if ($ssl === true) { if (($this->connexion = @ftp_ssl_connect($host, $port, $timeout)) === false) { throw new Exception('Impossible de se connecter au serveur FTP en SSL'); } } else { if (($this->connexion = @ftp_connect($host, $port, $timeout)) === false) { throw new Exception('Impossible de se connecter au serveur FTP ' . $host . ":{$port} {$timeout}"); } } } catch (\Exception $e) { // any unknown pb throw $e; } return $this; }