PHP FTPS在主机切换FTP域名后出现'遇到文件结束'的错误。

问题描述 投票:0回答:2

我已经连接到某一个使用FTPS的FTP多年了。最近我们被告知他们换了一个新域名,我们应该更新我们的代码。下面的代码在旧域名上总是能工作,但在新域名上却失败了。

        $ftp_server = 'ftps://newdomain.com/file.csv'; 
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, $ftp_server);
        curl_setopt($ch, CURLOPT_USERPWD,'user'.':'.'pass');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
        curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
        curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
        $file = fopen('data.csv', "w+");
        curl_setopt($ch, CURLOPT_FILE, $file);

        $data = curl_exec($ch);

        fputs($file, $data);
        curl_close($ch);
        //some code to read file

现在,连接似乎可以正常工作, 但它不能检索文件。Verbose显示。

< 230 Logged on
> PBSZ 0
< 200 PBSZ=0
> PROT P
< 200 Protection level set to P
> PWD
< 257 "/" is current directory.
* Entry path is '/'
> EPSV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
< 229 Entering Extended Passive Mode (|||35009|)
*   Trying xx.xx.xx.xxx...
* TCP_NODELAY set
* Connecting to xx.xx.xx.xxx (xx.xx.xx.xxx) port 35009
* Connected to ftp.newdomain.com (xx.xx.xx.xxx) port 990 (#0)
> TYPE I
< 200 Type set to I
> SIZE file.csv
< 213 5728398
> RETR file.csv
< 150 Opening data channel for file download from server of "/file.csv"
* Maxdownload = -1
* Getting file with size: 5728398
* Doing the SSL/TLS handshake on the data stream
* warning: ignoring value of ssl.verifyhost
* skipping SSL peer certificate verification
* NSS error -5938 (PR_END_OF_FILE_ERROR)
* Encountered end of file

除了服务器名,我什么都没改。有什么想法,这个错误意味着什么?我在2个不同的本地服务器上运行了这个程序,以排除是我的本地服务器的可能性。

我试着在代码中调整不同的SSL设置,但总是失败。

谢谢你的帮助

php curl ftps
2个回答
0
投票

你有没有试过改变PASV模式? 这通常是首先要尝试的事情之一。


0
投票

添加这一行就解决了。我不知道为什么

    curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_CONTROL);
© www.soinside.com 2019 - 2024. All rights reserved.