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 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数