I'm trying to upload a txt file (2KB in size) using PHP cURL to Sharefile via implicit FTPS, however I'm receiving:
Connection timed out after 30000 milliseconds
Closing connection 0
My code is below, any advice is appreciated:
$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);
The output array from curl_getinfo
is mostly empty values with the url set.
curl_setopt($ch, CURLOPT_STDERR, fopen('curl.txt', 'w+'));
outputs the following (shortened for this post):
* 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
My Answer:
It looks like you are setting the CURLOPT_TIMEOUT option to 30 seconds, which may not be enough time for the file to upload, especially if the connection is slow. You can try increasing the timeout value to see if that resolves the issue.
Additionally, you may want to check if there are any firewall or network restrictions that could be causing the connection timeout. Make sure that the FTP server is accessible from your server and that there are no restrictions in place.
You can also try adding the following options to your cURL request to see if it helps:
php
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
These options disable SSL certificate verification, which may be causing the timeout if the server's certificate is not valid.
If none of these solutions work, you may want to consider using a different FTP client library or tool to upload the file to Sharefile.
Rate this post
5 of 5 based on 7891 votesComments