duanmu6231 2018-11-28 01:36
浏览 102

PHP 5.3 FTP使用ftp_put上传JSON文件不上传

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制