0
votes

I have php code that generates an xml file from two database tables and saves the xml file to a directory in a website folder structure. The xml files are getting save correctly. After the file is saved it needs to be sent by ftp to an external ftp server folder.

function send_ftp($source_file, $destination_file)
{
// set up basic connection
$ftp_server = 'svr02.xxxxxxx.com';
$connection_id = ftp_connect('svr02.xxxxxxx.com'); 

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

// upload the file
$upload = ftp_put($connection_id, $destination_file, $source_file, 
FTP_ASCII); 

// close the FTP stream 
ftp_close($conn_id); 
}

The connection seems to be fine and I can also use the same connection and credentials in FileZilla to manually upload the xml file.

How can I track down what the problem is, and am I using the ftp_put method correctly?

Thanks for any help..

UPDATE 5/22/2017 I added a function to return a var_dump as content I can use in a string or email etc.

function var_dump_ret($mixed = null) {
  ob_start();
  var_dump($mixed);
  $content = ob_get_contents();
  ob_end_clean();
  return $content;
}

With that code, then I can get the var dump output

$login_result = @ftp_login($connection_id, $ftp_user_name, $ftp_user_pass); 
$dump_content = var_dump_ret(var_dump($login_result));
send_to_dev('ftp login result', $dump_content);

The var_dump for login result is 'null' even though it should be true or false. I don't think I am getting a good login at this point.

UPDATE 5/23/2017 Per advice I change to using var_export function to get my variables. ftp_connect is failing; returning false, so the code is not even opening an ftp stream. I know that an ftp server is not to have 'ftp://' in front of it, and I cannot think of anything else. This ftp code is running on shared hosting on GoDaddy. Do you think there is a problem with GoDaddy blocking it?

1
try dumping var_dump($connection_id, $destination_file, $source_file) before the put command to make sure all the parameter are correct. also what is the value of $upload after you run it ? - Rabin
Have you tried in binary mode? most ftp clients I think default to binary, yet you have FTP_ASCII. - pokeybit
Also ftp_close($conn_id); should be ftp_close($connection_id); Not that it will make much difference to your problem - pokeybit
What does var_dump($upload) show? Does ftp_put issue any PHP warning? What is format of the $destination_file? - Martin Prikryl
I edited my post - Ryan

1 Answers

1
votes

Godaddy shared server hosting blocks outbound connections for security purposes. That is why ftp_connect would not open a connection.