Solution to Transfer files by php ftp_put() : warning: ftp_put() [function.ftp-put]: Opening data connection

Posted by: 
Dominique De Cooman

The whole thing did not work without this line.

ftp_pasv($conn_id, true);

Apparently with some ftp accounts you need to transfer in passive mode. As usual not documented by the client.

The full excerpt:

function exporter_vdab_ftp($file_path,$file_name) {
// set up basic connection
$file $file_path '/'.$file_name;
$ftp_server VDAB_FTP_SERVER;
$conn_id ftp_connect($ftp_server);

// login with username and password
$ftp_user_name VDAB_FTP_USER;
$ftp_user_pass VDAB_FTP_PASS;
$login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
"FTP connection has failed!";
"Attempted to connect to $ftp_server for user $ftp_user_name";
  else {
"Connected to $ftp_server, for user $ftp_user_name";
//turn passive mode on

// upload the file
$upload ftp_put($conn_idVDAB_REMOTE_PATH '/' $file_name$fileFTP_BINARY);

// close the FTP stream

Add new comment

Who are you?

By knowing who you are you will be directed to a page where we have displayed all our drupal services relevant to your professional identity.