I have a json file where I want to upload it to an ftp account on different server. I have followed all the code of this function but still I get failed Upload! here is my code:
$con = ftp_connect('ftp.target-server.com');
$login = ftp_login($con, 'usr', 'pa55');
if (!$con || !$login) {
die('Connection attempt failed!');
}
$destination = 'my-target-file.json';
$source = 'my-source-file.json';
ftp_pasv($con, true) or die("Unable switch to passive mode"); //I have tried this option to force passive mode
$upload = ftp_put($con, $destination, $source, FTP_BINARY); //options: FTP_BINARY|FTP_ASCII and I have tried both
if (!$upload){
echo 'Upload failed!<br><br><br>';
}else{
echo "DONE!";
}
ftp_close($con);
I always get failure although everything seems OK. N.B.
- I have tried the access through filezilla ftp client and I managed to upload the file manually to target destination.
- The source server is using older PHP 5.3 but looks fine regarding the ftp_put function.
- Also I have tried my-target-file.txt instead of .json and also failed upload.
- I have tried couple of different shared hosting serveres as target server but no luck.
I will be grateful if someone can advise!
I have checked the last error using error_get_last(); and got:Array ( [type] => 2 [message] => ftp_put(): Type set to I [file] => /hermes/......../public/ftp.php [line] => 9 ). I can upload files normally through FTP client filezilla to the target server with the same credentials I am usingbut I can not with ftp_put() as it is not working