从FTP下载文件失败

时间:2014-11-05 02:00:58

标签: php ftp

在我来到这里发布问题之前,我检查了一些其他答案,我遇到了以下脚本的问题,无论我尝试过什么,即使在列出文件之后也不会从FTP下载文件在目录中(显然)

因为我有条理,我喜欢将所有内容简化为一个类,

class FTPHandler
{
    private $connection;

    public function FTPConnect($host, $user, $pass)
    {
        $ftp = ftp_connect($host);
        $login = ftp_login($ftp, $user, $pass) or die("FTP: Login Failed");
        if ($login) {
            $this->connection = array("host" => $host, "user" => $user, "pass" => $pass);
            return $ftp;
        }

        echo "FTP Login Failed";
    }
    public function ListAllFiles($stream, $dir)
    {
        ftp_pasv($stream, true);
        $ls = ftp_nlist($stream, $dir);
        return $ls;
    }

    public function get_conx_info() {
        return $this->connection;
    }
}

使用以下代码:

define("APP_DIR", "./app/");

$ftp = new FTPHandler();

$handle = $ftp->FTPConnect("ftp.example.com.au", "exampleuser", "examplepass");

$files = $ftp->ListAllFiles($handle, APP_DIR);

foreach ($files as $val)
{
    if ($val != "." && $val != ".." && $val != "processed") {

        $local_file     =   $val;
        $remote_file    =   APP_DIR.$val;

        if (ftp_get($handle, $local_file, $remote_file)) {
            echo "Successfully retrieved: $remote_file <br/>";
        }
        else
        {
            echo "Failed retrieving file: $remote_file <br/>";
        }

    }
}

我的回报永远是:

Failed retrieving file: ./app/adsl-1989-csv.csv 
Failed retrieving file: ./app/adsl-1989-sig.png 
Failed retrieving file: ./app/dd-1964-csv.csv 
Failed retrieving file: ./app/dd-1964-sig.png 
Failed retrieving file: ./app/dd-1967-csv.csv 
Failed retrieving file: ./app/dd-1967-sig.png 
Failed retrieving file: ./app/dd-1972-csv.csv 
Failed retrieving file: ./app/dd-1972-sig.png 
Failed retrieving file: ./app/dd-1973-csv.csv 
Failed retrieving file: ./app/dd-1973-sig.png 
Failed retrieving file: ./app/dd-1974-csv.csv 
Failed retrieving file: ./app/dd-1974-sig.png 
Failed retrieving file: ./app/dd-1975-csv.csv 
Failed retrieving file: ./app/dd-1975-sig.png 
Failed retrieving file: ./app/dd-1978-csv.csv 

任何帮助都非常受欢迎,因为我必须自动化,以减少每周数千人的预算。

1 个答案:

答案 0 :(得分:0)

我最终发现FTP服务器本身有问题。

错误是通过更改默认的活动端口来解决的,因为它丢弃了大部分数据包。

因此,如果有任何人遇到同样的问题,值得看看做同样的事情。

感谢您Fred -ii-尝试帮助我。