cURL Implicit FTPS Connection Timeout

327 views Asked by At

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
1

There are 1 answers

0
Misunderstood On

You may want to try adding CURLOPT_TRANSFERTEXT,true
I'd try something like this:

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

When I get in trouble I add these options
Usually your request header will give you some clues.

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