cURL隐式FTPS连接超时

6gpjuf90  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(255)

我试图通过隐式FTPS使用PHP cURL上传一个txt文件(大小为2KB)到Sharefile,但我收到:
连接在30000毫秒后超时
正在关闭连接0
我的代码如下,任何建议是赞赏:

$fp         = fopen($local_file, 'rw+');
$ftp_url    = 'ftps://subdomain.sharefileftp.com/'.$ftp_path;

$ch         = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $ftp_url);
curl_setopt($ch, CURLOPT_PORT, 990);
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$response = curl_exec($ch);
curl_close($ch);

curl_getinfo的输出数组大部分是设置了url的空值。
curl_setopt($ch, CURLOPT_STDERR, fopen('curl.txt', 'w+'));输出以下内容(本帖简称):

* Expire in 0 ms for 1 (transfer 0x56523a8e1070)
* Expire in 1 ms for 1 (transfer 0x56523a8e1070)
* TCP_NODELAY set
*   Trying X.X.X.X...
* Expire in 200 ms for 4 (transfer 0x56523a8e1070)
* Connection timed out after 30002 milliseconds
* Closing connection 0
aelbi1ox

aelbi1ox1#

您可能需要尝试添加CURLOPT_TRANSFERTEXT,true
我会尝试这样的方式:

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FTP_SSL,TRUE );
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
$file = 'example.txt';    
$fp = fopen($file, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://ftp.com/directory/'. $file);
curl_setopt($ch, CURLOPT_USERPWD, "user:pw");
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file));

当我遇到麻烦时,我会添加以下选项
通常您的请求标题会给予您一些线索。

curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_FAILONERROR,true);

curl_getinfo($ch, CURLINFO_HEADER_OUT); `

相关问题