示例#1
1
 /**
  * Establece la conceccion al servidor de FTP
  *
  * @param $servidor_ftp=host  $user=usuario $pass=password $modo=de conexxion por defecto en true
  * @return $id_con identificador de la conexion FTP
  */
 function conexion($servidor_ftp, $user, $pass, $modo = true, $puerto = 21, $tiempoEspera = 360)
 {
     // configurar una conexion o abortar
     // el arroba es para evitar los warning que salgan por pantalla
     if (empty($tiempoEspera)) {
         $tiempoEspera = 90;
     }
     @($id_con = ftp_connect($servidor_ftp, $puerto, $tiempoEspera));
     if (!$id_con || !isset($id_con)) {
         return false;
         //return false conexion no establecida
     } else {
         // Abrir la session con usuario y contraseña
         // el arroba es para evitar los warning que salgan por pantalla
         @($login_result = ftp_login($id_con, $user, $pass));
         if (!$login_result || !isset($login_result)) {
             return false;
             //return false el logueo no fue establecida
         }
     }
     // Habilita o deshabilita el modo pasivo. En modo pasivo, las conexiones de datos son
     // iniciadas por el cliente, en lugar del servidor. Puede requerirse si el cliente se
     // encuentra detrás de un firewall. ftp_pasv() únicamente puede llamarse después de
     // un inicio de sesión exitoso, de otra forma fallará.
     ftp_pasv($id_con, $modo);
     // Verifico que type UNIX (tambien lo toman como valor la mayoria de los servidores windows)
     $res = ftp_systype($id_con);
     //if($res != "UNIX") return false;
     // Se conect OK
     return $id_con;
 }
示例#2
0
文件: ftp.php 项目: jackycgq/bzfshop
 protected function connect()
 {
     // open connection
     if (!($this->cn = ftp_connect($this->host, $this->port))) {
         trigger_error(sprintf(self::TEXT_CONNECT, $this->host, $this->port));
     }
     // login
     if (!ftp_login($this->getConnection(), $this->user, $this->pass)) {
         $this->disconnect();
         trigger_error(sprintf(self::TEXT_LOGIN_FAILED, $this->user));
     }
     // passive mode
     if ($this->passive && !ftp_pasv($this->getConnection(), true)) {
         $this->disconnect();
         trigger_error(self::TEXT_PASSIVE_MODE);
     }
     // check path
     if ($this->path != '/') {
         if (!$this->isDir($this->path) && !$this->createDir($this->path)) {
             $this->disconnect();
             trigger_error(self::TEXT_MOUNT_DIR);
         }
         // switch directory
         if (!ftp_chdir($this->getConnection(), $this->path)) {
             $this->disconnect();
             trigger_error(sprintf(self::TEXT_CHANGE_DIR, $this->path));
         }
     }
 }
示例#3
0
 function connect($hostName, $userName, $password, $port = 21, $passiveMode = true, $attempt = 0)
 {
     $this->currentHostName = $hostName;
     $this->currentUserName = $userName;
     $this->currentPassword = $password;
     $this->currentPort = $port;
     $this->currentPassiveMode = $passiveMode;
     // br()->log('Connecting to ' . $hostName . ' as ' . $userName);
     try {
         if ($this->connectionId = ftp_connect($hostName, $port)) {
             if (ftp_login($this->connectionId, $userName, $password)) {
                 if (ftp_pasv($this->connectionId, $passiveMode ? true : false)) {
                     $this->currentDirectory = $this->getServerDir();
                 } else {
                     throw new Exception('Can not switch passive mode to ' . $passiveMode);
                 }
             } else {
                 throw new Exception('Can not connect to ' . $hostName . ' as ' . $userName);
             }
         } else {
             throw new Exception('Can not connect to ' . $hostName);
         }
     } catch (Exception $e) {
         if (!preg_match('/Login incorrect/', $e->getMessage()) && $attempt < $this->reconnectsAmount) {
             usleep(250000);
             $this->connect($hostName, $userName, $password, $port, $passiveMode, $attempt + 1);
         } else {
             throw new Exception('Can not connect to ' . $hostName . ': ' . $e->getMessage());
         }
     }
 }
示例#4
0
文件: Ftp.php 项目: rburch/core
 /**
  * Establish an FTP connection
  * 
  * @throws \Exception If an FTP connection cannot be established
  */
 public function connect()
 {
     if ($this->blnIsConnected) {
         return;
     }
     // Check the FTP credentials
     if ($GLOBALS['TL_CONFIG']['ftpHost'] == '') {
         throw new \Exception('The FTP host must not be empty');
     } elseif ($GLOBALS['TL_CONFIG']['ftpUser'] == '') {
         throw new \Exception('The FTP username must not be empty');
     } elseif ($GLOBALS['TL_CONFIG']['ftpPass'] == '') {
         throw new \Exception('The FTP password must not be empty');
     }
     $ftp_connect = $GLOBALS['TL_CONFIG']['ftpSSL'] && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
     // Try to connect
     if (($resConnection = $ftp_connect($GLOBALS['TL_CONFIG']['ftpHost'], $GLOBALS['TL_CONFIG']['ftpPort'], 5)) == false) {
         throw new \Exception('Could not connect to the FTP server');
     } elseif (ftp_login($resConnection, $GLOBALS['TL_CONFIG']['ftpUser'], $GLOBALS['TL_CONFIG']['ftpPass']) == false) {
         throw new \Exception('Authentication failed');
     }
     // Switch to passive mode
     ftp_pasv($resConnection, true);
     $this->blnIsConnected = true;
     $this->resConnection = $resConnection;
 }
示例#5
0
 /**
  * 连接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'));
 }
示例#6
0
 public function connect()
 {
     $this->printLog("Connect");
     if ($this->conn_id = ftp_connect($this->host, $this->port, $this->timeout)) {
         if (ftp_login($this->conn_id, $this->user, $this->pass)) {
             $this->updateState(PR_FTP_STATE_LOGGED_IN);
             if ($status = ftp_chdir($this->conn_id, $this->cur_path)) {
                 $this->updateState(PR_FTP_STATE_TARGETED);
                 $this->updateStatus(PR_FTP_STATUS_READY);
                 $this->systype = ftp_systype($this->conn_id);
                 // TODO: make specific OS dependednt things
                 $this->printLog("OS: " . $this->systype . " " . ftp_pwd($this->conn_id));
                 // TODO: pass the mode into the module
                 ftp_pasv($this->conn_id, true);
                 unset($this->listing_cache);
                 $this->listing_cache = array();
             } else {
                 $this->updateState(PR_FTP_STATE_ERROR);
             }
         } else {
             $this->updateState(PR_FTP_STATE_DISCONNECTED);
             $this->updateStatus(PR_FTP_STATUS_NOT_READY);
         }
     } else {
         $this->updateState(PR_FTP_STATE_DISCONNECTED);
         $this->updateStatus(PR_FTP_STATUS_NOT_READY);
     }
 }
示例#7
0
 /**
  * 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']);
 }
 private function ljg_ftp_login()
 {
     $conn = ftp_connect($this->ljg_ftp['ip']);
     ftp_login($conn, $this->ljg_ftp['login'], $this->ljg_ftp['pass']);
     ftp_pasv($conn, true);
     return $conn;
 }
 protected function _getConnexion($data)
 {
     if (!empty($this->conn)) {
         return $this->conn;
     }
     if (!array_key_exists('host', $data) || empty($data['host'])) {
         throw new InvalidArgumentException('Empty FTP server adress', 400);
     }
     if (!array_key_exists('port', $data) || empty($data['port'])) {
         throw new InvalidArgumentException('Empty FTP server port', 400);
     }
     if (!array_key_exists('user', $data)) {
         $data['user'] = '';
     }
     if (!array_key_exists('password', $data)) {
         $data['password'] = '';
     }
     $conn = ftp_connect($data['host'], $data['port']);
     if ($conn === false) {
         throw new \RuntimeException('Cannot connect to FTP server "' . $loginData['host'] . ':' . $loginData['port'] . '"', 502);
     }
     if (ftp_login($conn, $data['user'], $data['password'])) {
         // Turn passive mode on
         if (ftp_pasv($conn, true) === false) {
             throw new \RuntimeException('Cannot connect to FTP server "' . $loginData['host'] . ':' . $loginData['port'] . '" (cannot turn passive mode on)', 502);
         }
         $this->conn = $conn;
         return $conn;
     } else {
         throw new \RuntimeException('Cannot connect to FTP server "' . $loginData['host'] . ':' . $loginData['port'] . '" with username "' . $loginData['user'] . '" (authentification failed)', 401);
     }
 }
 function Connect($passive = TRUE)
 {
     $conn_id = ftp_connect($this->config->item('static_ftp_address'));
     ftp_login($conn_id, $this->config->item('static_ftp_username'), $this->config->item('static_ftp_password'));
     $mode = ftp_pasv($conn_id, $passive);
     return $conn_id;
 }
示例#11
0
 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;
 }
示例#12
0
function upload()
{
    $ftp_server = "ftp.webcindario.com";
    $ftp_user_name = "nngg";
    $ftp_user_pass = "******";
    $destination_file = "./img/";
    $source_file = $_FILES['userfile']['tmp_name'];
    $source_name = $_FILES['userfile']['name'];
    $conn_id = ftp_connect($ftp_server);
    ftp_pasv($conn_id, true);
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    if (!$conn_id || !$login_result) {
        echo "";
        echo "";
        exit;
    } else {
        echo "";
    }
    $upload = ftp_put($conn_id, $destination_file . $_FILES['userfile']['name'], $source_file, FTP_BINARY);
    if (!$upload) {
        echo "";
    } else {
        echo "";
    }
}
示例#13
0
 /**
  * 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;
 }
示例#14
0
function DeleteUpfile($R, $d)
{
    global $g, $table;
    $UPFILES = getArrayString($R['upload']);
    foreach ($UPFILES['data'] as $_val) {
        $U = getUidData($table['s_upload'], $_val);
        if ($U['uid']) {
            if ($U['url'] == $d['comment']['ftp_urlpath']) {
                $FTP_CONNECT = ftp_connect($d['comment']['ftp_host'], $d['comment']['ftp_port']);
                $FTP_CRESULT = ftp_login($FTP_CONNECT, $d['comment']['ftp_user'], $d['comment']['ftp_pass']);
                if ($d['comment']['ftp_pasv']) {
                    ftp_pasv($FTP_CONNECT, true);
                }
                if (!$FTP_CONNECT) {
                    getLink('', '', 'FTP서버 연결에 문제가 발생했습니다.', '');
                }
                if (!$FTP_CRESULT) {
                    getLink('', '', 'FTP서버 아이디나 패스워드가 일치하지 않습니다.', '');
                }
                ftp_delete($FTP_CONNECT, $d['comment']['ftp_folder'] . $U['folder'] . '/' . $U['tmpname']);
                if ($U['type'] == 2) {
                    ftp_delete($FTP_CONNECT, $d['comment']['ftp_folder'] . $U['folder'] . '/' . $U['thumbname']);
                }
                ftp_close($FTP_CONNECT);
            } else {
                unlink($U['url'] . $U['folder'] . '/' . $U['tmpname']);
                if ($U['type'] == 2) {
                    unlink($U['url'] . $U['folder'] . '/' . $U['thumbname']);
                }
            }
            getDbDelete($table['s_upload'], 'uid=' . $U['uid']);
        }
    }
}
示例#15
0
 /**
  * FTP Connect
  *
  * @access	public
  * @param	array	 the connection values
  * @return	bool
  */
 function connect($config = array())
 {
     if (count($config) > 0) {
         $this->initialize($config);
     }
     if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port))) {
         if ($this->debug == TRUE) {
             $this->_error('ftp_unable_to_connect');
         } else {
             $this->error = TRUE;
             $this->error_msg = 'ftp_unable_to_connect';
         }
         return FALSE;
     }
     if (!$this->_login()) {
         if ($this->debug == TRUE) {
             $this->_error('ftp_unable_to_login');
         } else {
             $this->error = TRUE;
             $this->error_msg = 'ftp_unable_to_login';
         }
         return FALSE;
     }
     // Set passive mode if needed
     if ($this->passive == TRUE) {
         ftp_pasv($this->conn_id, TRUE);
     }
     return TRUE;
 }
示例#16
0
 /**
  * @return bool
  * @throws \Exception
  */
 public function setPassiveMode()
 {
     if (false === ftp_pasv($this->getFtp(), true)) {
         throw new \Exception("Can't switch to PASSIVE mode in " . $this->getFtpHost());
     }
     return true;
 }
示例#17
0
 /**
  * Establish FTP connection
  * @param void
  * @return bool
  */
 public function connect()
 {
     $cf = $this->ssl === true ? 'ftp_ssl_connect' : 'ftp_connect';
     $this->connection = @$cf($this->host, $this->port, $this->timeout);
     if ($this->connection !== false) {
         $this->debugSet('400', 'Connection ok');
         $login = @ftp_login($this->connection, $this->user, $this->password);
         if ($login === true) {
             $this->debugSet('401', 'Login ok');
             if ($this->passive === true) {
                 $pasv = ftp_pasv($this->connection, true);
                 if ($login === true) {
                     $this->debugSet('402', 'Passive mode ok');
                 } else {
                     $this->debugSet('1402', 'Passive mode failed');
                 }
             }
             $this->status = true;
         } else {
             $this->debugSet('1401', 'FTP Login failed');
             ftp_close($this->connection);
             $this->connection = false;
         }
     } else {
         $this->debugSet('1400', 'FTP Connection failed');
     }
     return $this->status;
 }
示例#18
0
 private function uploadPackageToFTP($account)
 {
     $connection = @ftp_connect($account['host']);
     if (!$connection) {
         cmsUser::addSessionMessage(LANG_CP_FTP_AUTH_FAILED, 'error');
         return false;
     }
     $session = @ftp_login($connection, $account['user'], $account['pass']);
     if (!$session) {
         cmsUser::addSessionMessage(LANG_CP_FTP_AUTH_FAILED, 'error');
         return false;
     }
     if ($account['is_pasv']) {
         ftp_pasv($connection, true);
     }
     if (!$this->checkDestination($connection, $account)) {
         return false;
     }
     $src_dir = $this->getPackageContentsDir();
     $dst_dir = '/' . trim($account['path'], '/');
     try {
         $this->uploadDirectoryToFTP($connection, $src_dir, $dst_dir);
     } catch (Exception $e) {
         ftp_close($connection);
         cmsUser::addSessionMessage($e->getMessage(), 'error');
         return false;
     }
     ftp_close($connection);
     $this->redirectToAction('install/finish');
     return true;
 }
示例#19
0
 /**
  * Fetch data file from Itella FTP server
  * @param $type Data file type (PCF = localities, BAF = street addresses, POM = zip code changes)
  * @returns Temp file name
  */
 public function fetchFile($type)
 {
     //Connect to FTP server
     $ftp = ftp_connect($this->host);
     if ($ftp === false) {
         throw new Exception("Could not connect to '{$this->host}'");
     }
     if (!ftp_login($ftp, $this->user, $this->password)) {
         throw new Exception("Login to '{$this->host}' as '{$this->user}' failed");
     }
     //Find filename to download
     ftp_pasv($ftp, true);
     $list = ftp_nlist($ftp, '.');
     $file = null;
     foreach ($list as $item) {
         $parts = explode('_', $item);
         if (isset($parts[0]) && strtoupper($parts[0]) == strtoupper($type)) {
             $file = $item;
         }
     }
     if ($file == null) {
         throw new Exception("'{$type}' file not found");
     }
     //Download requested data file
     $tmpFile = tempnam(sys_get_temp_dir(), 'FinZip_' . $type . '_') . '.zip';
     $this->tmpFiles[] = $tmpFile;
     $tmp = fopen($tmpFile, 'w');
     ftp_pasv($ftp, true);
     ftp_fget($ftp, $tmp, $file, FTP_BINARY);
     ftp_close($ftp);
     fclose($tmp);
     //Return the filename of the temporary file
     return $tmpFile;
 }
示例#20
0
文件: ftp.php 项目: Nolfneo/docvert
function copyViaFtpRecursively($uploadLocation, $previewPath, $remoteDirectory, $ftpType)
{
    $errorMessage = '';
    $connectionId = getFtpConnection($uploadLocation['host'], $uploadLocation['username'], $uploadLocation['password'], $uploadLocation['port']);
    switch ($ftpType) {
        case 'active':
            ftp_pasv($connectionId, False);
            break;
        case 'passive':
            ftp_pasv($connectionId, True);
            break;
    }
    $baseDirectory = $uploadLocation['baseDirectory'];
    if (substr($baseDirectory, strlen($baseDirectory) - 1, 1) != '/') {
        $baseDirectory .= '/';
    }
    ftp_mkdir($connectionId, $baseDirectory);
    // No point showing an error message if the directory exists (most likely cause of error) because it will exist (at least) after the first time.
    $remoteBaseDirectory = $baseDirectory . $remoteDirectory;
    if (substr($remoteBaseDirectory, strlen($remoteBaseDirectory) - 1, 1) == '/') {
        $remoteBaseDirectory = substr($remoteBaseDirectory, 0, strlen($remoteBaseDirectory) - 1);
    }
    $remoteBaseDirectory .= '/';
    $errorMessage .= copyFileViaFtp($previewPath, $remoteBaseDirectory, $connectionId);
    ftp_close($connectionId);
    $errorHtml = '';
    if ($errorMessage) {
        $errorHtml = nl2br($errorMessage);
    }
    return $errorHtml;
}
示例#21
0
 /**
  * 方法:FTP连接
  * @FTP_HOST -- FTP主机
  * @FTP_PORT -- 端口
  * @FTP_USER -- 用户名
  * @FTP_PASS -- 密码
  */
 function __construct($FTP_HOST, $FTP_PORT, $FTP_USER, $FTP_PASS)
 {
     $this->conn_id = @ftp_connect($FTP_HOST, $FTP_PORT) or die("FTP服务器连接失败");
     @ftp_login($this->conn_id, $FTP_USER, $FTP_PASS) or die("FTP服务器登陆失败");
     @ftp_pasv($this->conn_id, 0);
     // 打开被动模拟
 }
示例#22
0
 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;
 }
示例#23
0
 /**
  * 构造函数,自动连接
  * @access public
  * @param array $config FTP选项
  */
 public function __construct($config)
 {
     if (!function_exists('ftp_connect')) {
         throw new SYException('Ext "FTP" is required', '10023');
     }
     if (!isset($config['port'])) {
         $config['port'] = 21;
     }
     //默认为被动模式
     if (!isset($config['pasv'])) {
         $config['pasv'] = TRUE;
     }
     if (FALSE === ($this->link = ftp_connect($config['host'], $config['port']))) {
         throw new SYException('Can not connect to FTP Server', '10040');
     }
     //登录
     if (isset($config['user'])) {
         if (!ftp_login($this->link, $config['user'], $config['password'])) {
             throw new SYException('Can not login to FTP Server', '10041');
         }
     } else {
         if (!ftp_login($this->link, 'anonymous', '')) {
             throw new SYException('Can not login to FTP Server as anonymous', '10041');
         }
     }
     if ($config['pasv']) {
         ftp_pasv($this->link, TRUE);
     }
     $this->config = $config;
 }
 /**
  * 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));
         }
     }
 }
示例#25
0
文件: Ftp.php 项目: nguyen113/Rai5
 /**
  * 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;
 }
示例#26
0
文件: Ftp.php 项目: alx/SBek-Arak
 /**
  * Connects to FTP server
  *
  * @param string $error
  * @return boolean
  */
 function _connect(&$error)
 {
     if (empty($this->_config['host'])) {
         $error = 'Empty host.';
         return false;
     }
     if (!isset($this->_config['port'])) {
         $this->_config['port'] = 21;
     }
     $this->_ftp = @ftp_connect($this->_config['host'], $this->_config['port'], W3_CDN_FTP_CONNECT_TIMEOUT);
     if (!$this->_ftp) {
         $error = sprintf('Unable to connect to %s:%d.', $this->_config['host'], $this->_config['port']);
         return false;
     }
     if (!@ftp_login($this->_ftp, $this->_config['user'], $this->_config['pass'])) {
         $this->_disconnect();
         $error = 'Incorrect login or password.';
         return false;
     }
     if (isset($this->_config['pasv']) && !@ftp_pasv($this->_ftp, $this->_config['pasv'])) {
         $this->_disconnect();
         $error = 'Unable to change mode to passive.';
         return false;
     }
     if (!empty($this->_config['path']) && !@ftp_chdir($this->_ftp, $this->_config['path'])) {
         $this->_disconnect();
         $error = sprintf('Unable to change directory to: %s.', $this->_config['path']);
         return false;
     }
     return true;
 }
 /**
  * Connect to ftp server
  *
  * @return bool
  **/
 protected function connect()
 {
     if (!($this->connect = ftp_connect($this->options['host'], $this->options['port'], $this->options['timeout']))) {
         return $this->setError('Unable to connect to FTP server ' . $this->options['host']);
     }
     if (!ftp_login($this->connect, $this->options['user'], $this->options['pass'])) {
         $this->umount();
         return $this->setError('Unable to login into ' . $this->options['host']);
     }
     // switch off extended passive mode - may be usefull for some servers
     //@ftp_exec($this->connect, 'epsv4 off' );
     // enter passive mode if required
     $this->options['mode'] = 'active';
     ftp_pasv($this->connect, $this->options['mode'] == 'passive');
     // enter root folder
     if (!ftp_chdir($this->connect, $this->root)) {
         $this->umount();
         return $this->setError('Unable to open root folder.');
     }
     $stat = array();
     $stat['name'] = $this->root;
     $stat['mime'] = 'directory';
     $this->filesCache[$this->root] = $stat;
     $this->cacheDir($this->root);
     return true;
 }
 function connect($config = array())
 {
     if (count($config) > 0) {
         $this->initialize($config);
     }
     if ($this->ssl_mode == TRUE) {
         if (function_exists('ftp_ssl_connect')) {
             $this->conn_id = @ftp_ssl_connect($this->hostname, $this->port, $this->timeout);
         } else {
             $this->_error('ftp_unable_to_connect');
         }
     } else {
         $this->conn_id = @ftp_connect($this->hostname, $this->port, $this->timeout);
     }
     if ($this->conn_id === FALSE) {
         if ($this->debug == TRUE) {
             $this->_error('ftp_unable_to_connect');
         }
         return FALSE;
     }
     if (!$this->_login()) {
         if ($this->debug == TRUE) {
             $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;
 }
示例#29
0
文件: ftp.php 项目: eduNeusoft/weixin
 /**
  * FTP连接
  *
  * @access 	public
  * @param 	array 	配置数组
  * @return	boolean
  */
 public function connect($config = array())
 {
     if (count($config) > 0) {
         $this->_init($config);
     }
     $funcname = $this->ssl && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
     if (!function_exists($funcname)) {
         return FALSE;
     }
     if (FALSE === ($this->conn_id = @$funcname($this->hostname, $this->port))) {
         if ($this->debug === TRUE) {
             $this->_error("ftp_unable_to_connect");
         }
         return FALSE;
     }
     if (!empty($this->timeout)) {
         $this->set_option(FTP_TIMEOUT_SEC, $this->timeout);
     }
     if (!$this->_login()) {
         if ($this->debug === TRUE) {
             $this->_error("ftp_unable_to_login");
         }
         return FALSE;
     }
     if ($this->passive === TRUE) {
         ftp_pasv($this->conn_id, TRUE);
     }
     return TRUE;
 }
示例#30
0
 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;
     }
 }