简体   繁体   English

CURL-通过TLS连接显式FTP

[英]CURL - Connect explicit FTP over TLS

I am trying to connect to FTP server using encryption as explicit FTP over TLS. 我正在尝试使用加密作为TLS上的显式FTP连接到FTP服务器。

curl_setopt($ch, CURLOPT_URL, 'ftp.mydomain.com/orders'.$filename);
curl_setopt($ch, CURLOPT_USERPWD, 'uname:pwd');
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_PORT, 21);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
$error_no = curl_errno($ch);

I have to upload the file to this location, but while connecting to the server, it gives the error number 56 (response reading failed). 我必须将文件上传到该位置,但是在连接到服务器时,它给出了错误号56(响应读取失败)。 I am not sure whether I am using the correct options to explicitly connect FTP over TLS. 我不确定我是否使用正确的选项通过TLS显式连接FTP。

Not only you didn't enable TLS/SSL. 不仅您没有启用TLS / SSL。 You didn't even specify what protocol to use. 您甚至都没有指定要使用的协议。 And CURL defaults to HTTP. CURL默认为HTTP。 So your code fails because CURL tries to talk HTTP to FTP server. 因此,您的代码将失败,因为CURL尝试将HTTP与FTP服务器通信。

To select FTP and force TLS/SSL: 要选择FTP并强制执行TLS / SSL,请执行以下操作:

curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_FTP);
curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_ALL);

Try with below code - 尝试以下代码-

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM