doumisha5081 2012-09-07 09:01
浏览 45
已采纳

为什么通过ftp_fput上传zip文件会返回true但不上传文件?

The following command returns true and uploads the text XML file to the FTP server:

if (ftp_put($this->ftpConnectionId, $this->remoteXmlFileName, $this->localXmlFileName, FTP_ASCII)) {

However, when I try to upload a .zip file intead of a text XML file, it still returns true but does not upload the file:

if (ftp_put($this->ftpConnectionId, $this->remoteXmlFileName, $this->localXmlFileName, FTP_BINARY)) {

I found that if I simply rename the zip file to ".xml", it WILL upload the file but the .zip file is corrupted.

But if I rename the zip file to ".zip.xml" it again returns true but does not upload the file.

What could be the reasons for this odd behavior?

Additional Info:

A zip file can be uploaded via FileZilla no problem with the same account.

I also am specifing:

ftp_pasv($this->ftpConnectionId, true);
  • 写回答

2条回答 默认 最新

  • dt3358 2012-09-07 09:10
    关注

    A zipfile is a binary file. That's probably why uploading it as .xml corrupts the file. Try specifying FTP_BINARY instead of FTP_ASCII. FTP_BINARY will work for ascii files too, but not vice versa, so you can better always use FTP_BINARY than always FTP_ASCII.

    The ftp server may reject the file for many reasons, so it may allow the upload at first, but then not save the file. The ascii/binary problem may be one, but also some file extensions may be blacklisted, or the file could be too big. The latter is unlikely, though, since uploading the zipfile with a different extensions worked for you.

    I think the ftp server actively ignores zip files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'
  • ¥15 r语言神经网络自变量重要性分析