1

I'm trying to upload a file to a ftp server and I'm having some trouble finding out why the upload is failing.

The following works fine on localhost, uploading my file to the server. Running it on my Azure server it does connect but fails to upload the file.

$file = 'some_file.xml';
$fp = fopen($file, 'r');
$conn_id = ftp_connect('my_ftpserver');

$login_result = ftp_login($conn_id, 'my_user', 'my_password');
if (ftp_fput($conn_id, 'my_filepath/'.$file, $fp, FTP_ASCII)){
    echo "Successfully uploaded $file\n";
}
else{
    echo "There was a problem while uploading $file\n";
}


ftp_close($conn_id);
fclose($fp);

I've checked that the account have permission to write files and that it does not require sftp. Anything else I should be taking a look at?

Also, I'm new to using ftp with PHP, is there any way I can get the server response codes to try and figure out why the command fails?

Any pointers would be greatly appreciated!

Jesper
  • 91
  • 7
  • Try to enable all the errors: `error_reporting(E_ALL); ini_set("display_errors", 1);`. PHP will show you the errors. – user4035 Apr 30 '14 at 07:22
  • I don't think its possible to get `error_codes` using `ftp_fput()` – Ravi Dhoriya ツ Apr 30 '14 at 07:22
  • That did display a warning, so that's good. Not a response code though code though. Got: Warning: ftp_fput(): Type set to A in [path to php-file] on line 18 (line 18 would be my ftp_fput) – Jesper Apr 30 '14 at 08:28
  • @Log1c if not possible with ftp_fput, any other approach to this you could recommend where it is possible? – Jesper Apr 30 '14 at 08:34
  • If you are serious about the file transfer and just starting then don't waste time on FTP as it is not secure at all and due to that unusable outside an intranet environment. Check e.g. http://stackoverflow.com/questions/4689540/how-to-sftp-with-php for some links – xmojmr May 01 '14 at 15:28

0 Answers0