0

I am currently working on a project that involves connecting to the clients FTPS server and downloading a file that they are updating automatically with the data we require. I am wanting to access this server via PHP so I can automate it.

The issue that I have is that FTP_SSL_CONNECT will NOT work due to the client using Implicit TLS security on the server.

Does anyone have any experience of getting this connection working?

Thanks, T

$username = 'username here';
$password = 'password here';
$get_file = "file to get here";
//set ftps url
$url = "ftps urls here";
$local_prefix = 'local folder prefix here';
$location = "ftps://" . $username . ":" . $password . "@" . $url;
$port = "any port number here";
//********************************************************************//
//initialize cURL and begin
print("Initializing cURl and saving file from scure ftp.");
$curl = curl_init();
//create or open a file for writing
$file = fopen("$local_prefix$get_file", "w");
//set cURL options *note* these must occur in order for implicit ftp to work correctly
curl_setopt($curl, CURLOPT_URL, "$location$get_file");
curl_setopt($curl, CURLOPT_PORT, "$port");
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_FILE, $file);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
curl_exec($curl) or die("did not save file");
curl_close ($curl);
fclose($file);
TeeJayEss
  • 151
  • 1
  • 12
  • 1
    Show us what you're trying... are you attempting to use a shell command via `exec`, streams, sockets, `file_get_contents` (does that even work with FTP?), or something else? – Kryten Jun 20 '14 at 15:04
  • I hate to link out of SO but:: https://gist.github.com/maxrice/4544344 – VikingBlooded Jun 20 '14 at 15:09
  • I found this code online (never a good idea I know) but I need to adapt it some way to work for me, I'm trying to get my PHP code to access the FTPS server, download the updated text file and then allow it to be used. I just keep getting timeouts (presumably due to not being able to connect more than anything) – TeeJayEss Jun 20 '14 at 15:10
  • Put the code in the question, not in comments. And use the code formatting. – Patrick Q Jun 20 '14 at 15:11
  • see I looked at that one @VikingBlooded but then couldn't get it to work for me – TeeJayEss Jun 20 '14 at 15:12
  • `curl_exec($curl) or die(curl_error($curl))` will give you much better diagnostics than a pretty useless "didn't work" string. – Marc B Jun 20 '14 at 15:15
  • using the link I showed you, it took all of 2 minutes to create, move to web server and test. It worked just fine connecting to mine. – VikingBlooded Jun 20 '14 at 15:22
  • I put all my correct details into it and it still timed out – TeeJayEss Jun 20 '14 at 15:23

1 Answers1

0

You need to add these option to curl call

CURLOPT_FTP_SSL        => CURLFTPSSL_ALL, // require SSL For both control and data      connections
CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT, // let cURL choose the FTP authentication method (either SSL or TLS)
Sean Keane
  • 411
  • 1
  • 6
  • 19