tags:

views:

232

answers:

2

I have asked the question before but in a different manner. I am trying taking form data, compiling into a temporary CSV file and trying to send over to a client via FTP over SSL (this is the only route I am interested in hearing solutions for unless there is a workaround to doing this, I cannot make changes). I have tried the following:

  1. ftp_connect - nothing happens, the page just times out
  2. ftp_ssl_connect - nothing happens, the page just times out
  3. curl library - same thing, given URL it also gives error.

I am given the following information:

  • FTPS Server IP Address
  • TCP Port (1234)
  • Username
  • Password
  • Data Directory to dump file
  • FTP Mode: Passive

very, very basic code (which I believe should initiate a connection at minimum): Code:

<?php
$ftp_server = "00.000.00.000";  //masked for security
$ftp_port = "1234"; // masked but not 990
$ftp_user_name = "username";
$ftp_user_pass = "password";


// set up basic ssl connection
$conn_id = ftp_ssl_connect($ftp_server, $ftp_port, "20");

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);

echo ftp_pwd($conn_id); // /
echo "hello";

// close the ssl connection
ftp_close($conn_id);

?>

When I run this over a SmartFTP client, everything works just fine. I just can't get it to work using PHP (which is a necessity). Has anybody had success doing this in the past? I would be very interested to hear your approach.

EDIT I added the ftp_pasv() command after ftp_login as mentioned below but am still unable to connect. I am given the following errors:

Warning: ftp_login() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 12

Warning: ftp_pasv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 14

Warning: ftp_pwd() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 16

Warning: ftp_close() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 20

A: 

Is FTP enabled in your PHP installation? Use phpinfo(); to echo your installation info. There should be a section for ftp, with "FTP Support - enabled" in a table.

Dan Heberden
@Dan - yes FTP Support is enabled
JM4
A: 

First, you need to find out which secure FTP you are using,

  1. SFTP : SSH FTP
  2. FTPS : FTP over SSL

For FTPS to work, the openssl module must be statically linked (not installed as a dynamic extension).

SFTP requires PECL ssh2 extension.

ZZ Coder
@ZZ Coder - As the question states, I'm looking for 2 - FTPS - FTP over SSL. I'm not sure what 'statically linked' means in this terms of this question.
JM4
Check your php.ini, if you see something like "extension=openssl.so", it's dynamic. FTPS doesn't work with dynamic extensions. But this is probably not your problem. We get errors right away, not hanging.
ZZ Coder
@ZZ Coder - this extension doesn't exit on my system so I dont think it's the cause of the error
JM4
Check a similar line for FTP also. Both needs to be static. Another suggestion is to try CURL with a syntax like "ftps://host:port/path/file".
ZZ Coder