我正在尝试使用 PHP 中的 cURL 通过 tls 连接上传带有显式 ftp 的文件。使用 ftp 服务器的身份验证成功,但是当我尝试以被动模式上传文件时,我收到以下错误:“连接到 server.domain.nl:21 时出现未知的 SSL 协议(protocol)错误”。
在这种情况下可能是什么问题?会不会是被动上传的端口被我的供应商屏蔽了?我可以更改文件上传的端口吗?
我的网站提供商不支持 ftp_ssl_connect,所以我无法使用该功能。
谢谢, jack
FTP 日志:
230 User logged in.
PBSZ 0
< 200 PBSZ command successful.
PROT P
< 200 PROT command successful.
PWD
< 257 "/" is current directory.
* Entry path is '/'
CWD avs
< 250 CWD command successful.
EPSV
* Connect data stream passively
< 229 Entering Extended Passive Mode (|||50075|)
* Trying x.x.x.x...
* Connecting to x.x.x.x (x.x.x.x) port 50075
TYPE I
< 200 Type set to I.
STOR 00191_2773.xml < 150 Opening BINARY mode data connection.
* Doing the SSL/TLS handshake on the data stream
* successfully set certificate verify locations:
* CAfile: c:\vevida\php54\cacert.pem
CApath: none
* SSL re-using session ID
* Unknown SSL protocol error in connection to server.domain.nl:21
* Closing connection 19
我的代码是:
$ch = curl_init() ;
$stderr = fopen("d:\\www\\domein.nl\\www\\pdf\\temp\\curl.txt", "w");
$fp = fopen($fileLocation191, 'r') ;
//logging:
curl_setopt($ch, CURLOPT_VERBOSE, TRUE) ;
curl_setopt($ch, CURLOPT_STDERR, $stderr) ;
curl_setopt($ch, CURLOPT_URL, 'ftp://user:pw@server.domein.nl/avs/'.$remote_file191) ;
curl_setopt($ch, CURLOPT_UPLOAD, TRUE) ;
curl_setopt($ch, CURLOPT_INFILE, $fp) ;
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($fileLocation191)) ;
curl_setopt($ch, CURLOPT_PORT, 21) ;
curl_setopt($ch, CURLOPT_USERPWD, 'user:pw');
// SSL STUFF
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false) ;
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false) ;
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1) ;
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1') ;
curl_setopt($ch, CURLOPT_FTP_SSL, CURLOPT_FTPSSLAUTH) ;
curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS) ;
// EINDE SSL
//curl_setopt($ch, CURLOPT_FTPPORT, '-') ;
curl_setopt($ch, CURLOPT_TIMEOUT, 30) ;
curl_setopt($ch, CURLOPT_FTP_USE_EPSV, TRUE) ;
curl_setopt($ch, CURLOPT_FTP_USE_PASV, TRUE) ;
curl_setopt($ch, CURLOPT_FTP_USE_EPRT, FALSE) ;
curl_exec ($ch) ;
最佳答案
Could it be that the port for the passive upload is blocked by my provider?
可能是提供商只允许很少的传出端口,但我对此表示怀疑。询问供应商。
Can i change the port for the file upload?
不是,这个端口是由FTP服务器决定的。
一些你应该检查的东西:
- 尝试使用普通 FTP 查明问题是否与基于 TLS 的 FTP 有关。
- 尝试使用不同的 FTP 服务器。
- 尝试使用不同的程序访问服务器。
除此之外:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false) ;
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false) ;
你为什么要使用 TLS,因为你无论如何都禁用对等点的验证?或者这只是为了测试?
关于php - 使用 cURL 的 ftp 上传中的未知 SSL 协议(protocol)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26633776/