簡體   English   中英

PHPSeclib即使存在也無法下載文件

[英]PHPSeclib Unable to Download File even tho it exist

我似乎無法理解為什么文件確實存在時沒有下載。 這是我的代碼。

文件下載.PHP

use \Logic\FTPConnection;
$ftpPath= 'path/to/file.txt';
$localPath = 'temp/file.txt';

$objFTPCon = new FTPConnection(FTP_HOST, FTP_USER, FTP_PASS);
$objFTPCon->openConnection();
$exist = $objFTPCon->isFileExist($ftpPath); // this returns as true
$objFTPCon->downloadFile($localPath , $ftpPath); // not downloading

FTP連接.php

public function openConnection() // DONE
{
    if (!$this->ftpOpen) {
        
        $this->objConn = new SFTP($this->strHost);
        if ($this->objConn === false) {
            throw new \Exception('Unable to connect to SFTP server.');
        }

        if (!$this->objConn->login($this->strUser, $this->rsa)) {
            throw new \Exception('Unable to login to SFTP server.');
        }
        $this->ftpOpen = true;
    }
}

public function isFileExist($p_strFile) 
{
    $this->openConnection();
    $strStandardizedPath = $this->standardizePath($p_strFile);

    $blnFileExist = false;
    
    $strFile = substr($strStandardizedPath, strrpos($strStandardizedPath, '/') + 1);
    $strPath = substr($strStandardizedPath, 0, strrpos($strStandardizedPath, '/'));
    
    if ($this->isPathExist($strPath)) {
        $arrFileList = $this->objConn->nlist($strPath);
        if ($arrFileList) {
            if (in_array($strFile, $arrFileList)) {
                $blnFileExist = true;
            }
        }
    }
    
    return $blnFileExist;
}

public function downloadFile($p_strTargetFile, $p_strSourceFile)
{
    $this->openConnection();
    // $this->objConn->get($p_strTargetFile, $p_strSourceFile, FTP_BINARY);
    if (!$this->objConn->get($p_strTargetFile, $p_strSourceFile, FTP_BINARY)) {
        throw new \Exception('Unable to download file.');
    }
}

看來我的 get() 參數是錯誤的。 我剛剛換了它,它的工作原理:

所以而不是:

$this->objConn->get($p_strTargetFile, $p_strSourceFile, FTP_BINARY);

我用了:

$this->objConn->get($p_strSourceFile, $p_strTargetFile);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM