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


PHP Net_SFTP::_disconnect方法代码示例

本文整理汇总了PHP中Net_SFTP::_disconnect方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_SFTP::_disconnect方法的具体用法?PHP Net_SFTP::_disconnect怎么用?PHP Net_SFTP::_disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Net_SFTP的用法示例。


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

示例1: downloadFromFulfillment

 public function downloadFromFulfillment()
 {
     $arrayCsvFiles = array();
     $arrayCsvFilesClear = array();
     $sql = "SELECT *\n                FROM `fulfillment_files`\n                WHERE `fulfillment_id`=?i";
     $result = self::$_msql->getInd('filename', $sql, $this->fulfillment_id);
     if ($this->ssl) {
         $sftp = new Net_SFTP($this->server);
         if (!$sftp->login($this->username, $this->password)) {
             exit('Login Failed');
         }
         //$contents = $sftp->nlist("{$this->download_path}");
         $dPath = trim($this->download_path, '/');
         $contents = $sftp->nlist("{$dPath}");
         if (!$contents) {
             return;
         }
         foreach ($contents as $file) {
             if (substr($file, -4, 4) == '.csv') {
                 $arrayCsvFiles[] = $arrayCsvFilesClear[] = $file;
             }
         }
         foreach ($arrayCsvFiles as $file) {
             $tF = explode('/', $file);
             $fName = array_pop($tF);
             if (isset($result["{$fName}"])) {
                 continue;
             }
             $downloadFilePath = AF::path(time() . rand(1, 1000), array('files', 'csv', 'temp'), 'csv');
             if ($sftp->get($dPath . '/' . $file, $downloadFilePath)) {
                 self::parserCsvFiles($downloadFilePath);
                 $sql = "INSERT INTO `fulfillment_files` (`fulfillment_id`, `filename`, `time`) VALUES (?i, ?s, NOW())";
                 self::$_msql->query($sql, $this->fulfillment_id, $fName);
             }
         }
         $sftp->_disconnect(0);
     } else {
         $ftp = ftp_connect($this->server, $this->port, 300);
         if (!$ftp) {
             return;
         }
         if ($this->username && $this->password) {
             ftp_login($ftp, $this->username, $this->password);
         }
         ftp_pasv($ftp, true);
         // Passive mode
         $contents = ftp_nlist($ftp, "{$this->download_path}");
         if (!$contents) {
             return;
         }
         foreach ($contents as $file) {
             if (substr($file, -4, 4) == '.csv') {
                 $file = str_replace('\\', '/', $file);
                 $arrayCsvFiles[] = $file;
                 $tF = explode('/', $file);
                 $arrayCsvFilesClear[] = (string) trim(array_pop($tF));
             }
         }
         foreach ($arrayCsvFiles as $file) {
             $tF = explode('/', $file);
             $fName = (string) trim(array_pop($tF));
             if (isset($result["{$fName}"])) {
                 continue;
             }
             $downloadFilePath = AF::path(time() . rand(1, 1000), array('files', 'csv', 'temp'), 'csv');
             if (ftp_get($ftp, $downloadFilePath, $file, FTP_ASCII)) {
                 self::parserCsvFiles($downloadFilePath);
                 $sql = "INSERT INTO `fulfillment_files` (`fulfillment_id`, `filename`, `time`) VALUES (?i, ?s, NOW())";
                 self::$_msql->query($sql, $this->fulfillment_id, $fName);
             }
         }
         ftp_close($ftp);
     }
     $sql = "DELETE FROM `fulfillment_files`\n                WHERE `fulfillment_id` = ?i\n                AND `filename` NOT IN (?a)";
     self::$_msql->query($sql, $this->fulfillment_id, $arrayCsvFilesClear);
 }
开发者ID:,项目名称:,代码行数:76,代码来源:

示例2: parse_csv_file

        $arrayCsvFiles[] = $arrayCsvFilesClear[] = $file;
    }
}
foreach ($arrayCsvFiles as $file) {
    if (isset($result["{$file}"])) {
        continue;
    }
    $localFileNeme = time() . rand(1, 1000);
    $downloadFilePath = AF::path($localFileNeme, array('files', 'csv', 'rockets'), 'csv');
    if ($sftp->get($dPath . '/' . $file, $downloadFilePath)) {
        parse_csv_file($downloadFilePath);
        $sql = "INSERT INTO `fulfillment_files` (`fulfillment_id`, `filename`, `time`) VALUES (?i, ?s, NOW())";
        $msql->query($sql, $fulfillmentID, $file);
    }
}
$sftp->_disconnect(0);
function parse_csv_file($downloadFilePath)
{
    global $fulfillmentID, $msql;
    $header = NULL;
    $data = array();
    if (($handle = fopen($downloadFilePath, 'r')) !== FALSE) {
        while (($row = fgetcsv($handle, 1000, ',')) !== FALSE) {
            if (!$header) {
                $header = $row;
            } else {
                $data[] = array_combine($header, $row);
            }
        }
        fclose($handle);
    }
开发者ID:,项目名称:,代码行数:31,代码来源:


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