当前位置: 首页>>代码示例>>PHP>>正文


PHP ftp_ssl_connect函数代码示例

本文整理汇总了PHP中ftp_ssl_connect函数的典型用法代码示例。如果您正苦于以下问题:PHP ftp_ssl_connect函数的具体用法?PHP ftp_ssl_connect怎么用?PHP ftp_ssl_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ftp_ssl_connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * 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));
         }
     }
 }
开发者ID:daanbakker1995,项目名称:vanteun,代码行数:42,代码来源:class-wc-customer-order-csv-export-method-ftp.php

示例2: Authenticate

 /**
  * 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;
     }
 }
开发者ID:hamishcampbell,项目名称:silverstripe-auth-external,代码行数:44,代码来源:FTP.php

示例3: test_connection

 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>&nbsp;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>&nbsp;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>&nbsp;Username and Password is incorrect');
         } else {
             $output = array('status' => 'success', 'output' => '<span class="cus-accept"></span>&nbsp;Connection OK!');
         }
         ftp_close($conn_id);
         echo json_encode($output);
     } else {
         show_404();
     }
 }
开发者ID:braxtondiggs,项目名称:Clefable,代码行数:26,代码来源:ftp.php

示例4: open

 /**
  * 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=' . $this->conf['login'] . ' password=' . mb_substr($this->conf['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']);
 }
开发者ID:RolandKujundzic,项目名称:rkphplib,代码行数:35,代码来源:FTP.class.php

示例5: connect

 /**
  * 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());
         }
     }
 }
开发者ID:filicious,项目名称:ftp,代码行数:28,代码来源:FTPFilesystem.php

示例6: connect

 /**
  * 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;
 }
开发者ID:grimsmath,项目名称:lavillafdn,代码行数:39,代码来源:devdemon_ftp.php

示例7: connect

 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;
 }
开发者ID:Trideon,项目名称:gigolo,代码行数:33,代码来源:fileSystemFTPExt.php

示例8: connect

 /**
  * 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;
 }
开发者ID:nguyen113,项目名称:Rai5,代码行数:34,代码来源:Ftp.php

示例9: connect

 /**
  * 连接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'));
 }
开发者ID:HUST-CA,项目名称:Hustca-Ncre,代码行数:36,代码来源:ftp.cls.php

示例10: _connect

 /**
  * 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;
 }
开发者ID:radekstepan,项目名称:PumpedBlog,代码行数:33,代码来源:FTP.php

示例11: __construct

 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;
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:33,代码来源:ftpclient.php

示例12: __construct

 /**
  * @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());
     }
 }
开发者ID:rsms,项目名称:phpab,代码行数:31,代码来源:FTPConnection.php

示例13: connect

 /**
  * 
  * @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;
 }
开发者ID:rtsantos,项目名称:mais,代码行数:38,代码来源:Ftp.php

示例14: getListing

 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;
 }
开发者ID:densem-2013,项目名称:exikom,代码行数:60,代码来源:ftpbrowsers.php

示例15: connectSsl

 /**
  * 建立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}");
     }
 }
开发者ID:tiger2soft,项目名称:LycPHP,代码行数:11,代码来源:FtpAbstract.class.php


注:本文中的ftp_ssl_connect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。