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


PHP ftp_login函数代码示例

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


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

示例1: conexion

 /**
  * 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;
 }
开发者ID:Nilphy,项目名称:moteguardian,代码行数:37,代码来源:clase.FTPDriver.php

示例2: connect

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

示例3: connect

 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());
         }
     }
 }
开发者ID:jagermesh,项目名称:bright,代码行数:31,代码来源:BrFTP.php

示例4: connect

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

示例5: xmlFtpTest

 public function xmlFtpTest($xmlFileID)
 {
     $ftp_server = "117.55.235.145";
     $conn_id = ftp_connect($ftp_server);
     $ftp_user_name = "s1057223";
     $ftp_user_pass = "526Ge0P4Ck8Jd937";
     // login with username and password
     $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
     // check connection
     if (!$conn_id || !$login_result) {
         // echo "FTP connection has failed!";
         // echo "Attempted to connect to $ftp_server for user $ftp_user_name";
         // exit;
     } else {
         // echo "Connected to $ftp_server, for user $ftp_user_name";
     }
     $target_dir = public_path('assets/data/');
     $destination_file = "/public_html/test1/" . $xmlFileID . ".xml";
     $source_file = $target_dir . $xmlFileID . ".xml";
     // upload the file
     $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
     // check upload status
     if (!$upload) {
         echo "FTP upload has failed!";
     } else {
         // echo "Uploaded $source_file to $ftp_server as $destination_file";
     }
     // close the FTP stream
     ftp_close($conn_id);
 }
开发者ID:ianliu2015,项目名称:DocsLiquor,代码行数:30,代码来源:DataSyncController.php

示例6: __construct

 /**
  * 构造函数,自动连接
  * @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;
 }
开发者ID:sm115,项目名称:SYFramework,代码行数:35,代码来源:YFtp.php

示例7: __construct

 /**
  * 方法: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);
     // 打开被动模拟
 }
开发者ID:nick198205,项目名称:yiqixiu,代码行数:14,代码来源:Ftp.class.php

示例8: 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

示例9: downloadFile

 public function downloadFile()
 {
     $requestURL = trim(Mage::getStoreConfig('pulliver/western_power/base_url'), ' /');
     $username = Mage::getStoreConfig('pulliver/western_power/username');
     $password = Mage::getStoreConfig('pulliver/western_power/password');
     $connection = ftp_connect($requestURL);
     if (!$connection) {
         Vikont_Pulliver_Helper_Data::inform(sprintf('Could not connect to %s', $requestURL));
     }
     if (!@ftp_login($connection, $username, $password)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('Error logging to FTP %s as %s', $requestURL, $username));
     }
     $remoteFileName = Mage::getStoreConfig('pulliver/western_power/remote_filename');
     $localFileName = $this->getLocalFileName($remoteFileName, 'downloaded/');
     if (file_exists($localFileName)) {
         @unlink($localFileName);
     } else {
         if (!file_exists($dirName = dirname($localFileName))) {
             mkdir($dirName, 0777, true);
         }
     }
     Vikont_Pulliver_Helper_Data::type("Downloading {$requestURL}/{$remoteFileName}...");
     $startedAt = time();
     if (!ftp_get($connection, $localFileName, $remoteFileName, FTP_BINARY)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('Error downloading from FTP %s/%s to %s', $requestURL, $remoteFileName, $localFileName));
     }
     ftp_close($connection);
     $timeTaken = time() - $startedAt;
     Vikont_Pulliver_Helper_Data::inform(sprintf('Inventory successfully downloaded from %s/%s to %s, size=%dbytes, time=%ds', $requestURL, $remoteFileName, $localFileName, filesize($localFileName), $timeTaken));
     return $localFileName;
 }
开发者ID:rcclaudrey,项目名称:dev,代码行数:31,代码来源:WesternPower.php

示例10: subida_script

function subida_script($ftp_server, $ftp_user, $ftp_pass)
{
    // set up basic connection
    $conn_id = ftp_connect($ftp_server);
    if (!$conn_id) {
        echo "<div class='alert alert-warning' style='width:300px;margin:auto'>Connection established</div>";
    }
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
    if ($login_result) {
        echo "<div class='alert alert-success' style='width:300px;margin:auto'>Connection established</div>";
    }
    ftp_chdir($conn_id, 'public_html');
    ftp_mkdir($conn_id, 'search');
    ftp_chdir($conn_id, 'search');
    ftp_mkdir($conn_id, 'css');
    ftp_chdir($conn_id, 'css');
    echo ftp_pwd($conn_id);
    ftp_chdir($conn_id, '../../autotienda/search');
    echo ftp_pwd($conn_id);
    //Uploading files...
    //to be uploaded
    $file = "search/.htaccess";
    $fp = fopen($file, 'r');
    ftp_fput($conn_id, $file, $fp, FTP_ASCII);
    echo ftp_pwd($conn_id);
    // close the connection
    ftp_close($conn_id);
    fclose($fp);
}
开发者ID:nuwem,项目名称:fitness,代码行数:30,代码来源:libconfig.php

示例11: 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

示例12: syncFolderToFtp

function syncFolderToFtp($host, $username, $password, $remote_backup, $backup_folder)
{
    $ftp = ftp_connect($host);
    // connect to the ftp server
    ftp_login($ftp, $username, $password);
    // login to the ftp server
    ftp_chdir($ftp, $remote_backup);
    // cd into the remote backup folder
    // copy files from folder to remote folder
    $files = glob($backup_folder . '*');
    $c = 0;
    $allc = count($files);
    foreach ($files as $file) {
        $c++;
        $file_name = basename($file);
        echo "\n {$c}/{$allc}: {$file_name}";
        $upload = ftp_nb_put($ftp, $file_name, $file, FTP_BINARY);
        // non-blocking put, uploads the local backup onto the remote server
        while ($upload == FTP_MOREDATA) {
            // Continue uploading...
            $upload = ftp_nb_continue($ftp);
        }
        if ($upload != FTP_FINISHED) {
            echo " ... ERROR";
        } else {
            echo " ... OK";
        }
    }
    ftp_close($ftp);
    // closes the connection
}
开发者ID:mtancek,项目名称:php-sync-folder-to-remote-ftp,代码行数:31,代码来源:index.php

示例13: uploadPackageToFTP

 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;
 }
开发者ID:asphix,项目名称:icms2,代码行数:31,代码来源:install_ftp.php

示例14: save

 /**
  * Salva o conteúdo do arquivo no servidor Oracle
  * Caso seja possível salvar o arquivo, será retornado
  * o filename completo de onde o arquivo será armazenado
  * 
  * @param Zend_Db $db
  * @return string
  */
 public function save($db = null)
 {
     if ($db == null) {
         $db = Zend_Registry::get('db.projta');
     }
     if ($this->_content instanceof ZendT_Type_Blob) {
         $sql = "\n                    declare\n                      v_blob BLOB;\n                    begin\n                       insert into tmp_blob(content) values (:content);\n                       select content into v_blob FROM tmp_blob;\n                       arquivo_pkg.write_to_disk(p_data => v_blob,\n                                                 p_file_name => :name,\n                                                 p_path_name => :path);\n                    end;                \n                ";
         @($conn = ftp_connect('192.168.1.251'));
         if (!$conn) {
             throw new ZendT_Exception(error_get_last());
         }
         @($result = ftp_login($conn, 'anonymous', 'anonymous'));
         if (!$result) {
             throw new ZendT_Exception(error_get_last());
         }
         $fileNameServer = 'pub/temp/' . $this->_name;
         @ftp_delete($conn, $fileNameServer);
         @($result = ftp_put($conn, $fileNameServer, $this->_fileName, FTP_BINARY));
         if (!$result) {
             throw new ZendT_Exception(error_get_last() . ". Name Server: {$fileNameServer} || Name Local: {$this->_fileName}");
         }
         @($result = ftp_close($conn));
     } else {
         $sql = "\n                    begin\n                    arquivo_pkg.write_to_disk(p_data => :content,\n                                              p_file_name => :name,\n                                              p_path_name => :path);\n                    end;                \n                ";
         $stmt = $db->prepare($sql);
         $stmt->bindValue(':content', $this->_content);
         $stmt->bindValue(':name', $this->_name);
         $stmt->bindValue(':path', $this->_path);
         $stmt->execute();
     }
     $filename = $this->_path . '/' . $this->_name;
     return $filename;
 }
开发者ID:rtsantos,项目名称:mais,代码行数:41,代码来源:Attachment.php

示例15: sync

 /**
  * (non-PHPDoc)
  *
  * @see    \phpbu\App\Backup\Sync::sync()
  * @param  \phpbu\App\Backup\Target $target
  * @param  \phpbu\App\Result        $result
  * @throws \phpbu\App\Backup\Sync\Exception
  */
 public function sync(Target $target, Result $result)
 {
     // silence ftp errors
     $old = error_reporting(0);
     if (!($ftpConnection = ftp_connect($this->host))) {
         throw new Exception(sprintf('Unable to connect to ftp server %s', $this->host));
     }
     if (!ftp_login($ftpConnection, $this->user, $this->password)) {
         error_reporting($old);
         throw new Exception(sprintf('authentication failed for %s@%s%s', $this->user, $this->host, empty($this->password) ? '' : ' with password ****'));
     }
     $remoteFilename = $target->getFilename();
     $localFile = $target->getPathname();
     if ('' !== $this->remotePath) {
         $remoteDirs = explode('/', $this->remotePath);
         foreach ($remoteDirs as $dir) {
             if (!ftp_chdir($ftpConnection, $dir)) {
                 $result->debug(sprintf('creating remote dir \'%s\'', $dir));
                 ftp_mkdir($ftpConnection, $dir);
                 ftp_chdir($ftpConnection, $dir);
             } else {
                 $result->debug(sprintf('change to remote dir \'%s\'', $dir));
             }
         }
     }
     $result->debug(sprintf('store file \'%s\' as \'%s\'', $localFile, $remoteFilename));
     if (!ftp_put($ftpConnection, $remoteFilename, $localFile, FTP_BINARY)) {
         $error = error_get_last();
         $message = $error['message'];
         throw new Exception(sprintf('error uploading file: %s - %s', $localFile, $message));
     }
     error_reporting($old);
 }
开发者ID:todiadiyatmo,项目名称:phpbu,代码行数:41,代码来源:Ftp.php


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