apache FTP 上传问题 - 传输了 0 个字节
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1066437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FTP Upload Problem - 0 bytes transfered
提问by Srinivas
In one of our project we are using Apache's FTP client APIs. I have to upload xml file to a FTP server, where a process will keep polling that server directory. So using the upload API, I am uploading the xml file with .TRANSFER extension, and after successfully uploading full file, the file will be renamed to .xml file.
在我们的一个项目中,我们使用 Apache 的 FTP 客户端 API。我必须将 xml 文件上传到 FTP 服务器,其中一个进程将继续轮询该服务器目录。所以使用上传API,我上传扩展名为.TRANSFER 的xml 文件,成功上传完整文件后,该文件将重命名为.xml 文件。
The weird problem I am facing was that, sometimes the file size of the file is 0 bytes. but the same file sometimes fully gets uploaded. When I looked at log file, the transfered bytes are 0 kb only. So I am not sure what could be the problem.
我面临的奇怪问题是,有时文件的文件大小为 0 字节。但有时会完全上传相同的文件。当我查看日志文件时,传输的字节仅为 0 kb。所以我不确定可能是什么问题。
I am using linux server and Apache's commons's FTP client APIs.
我正在使用 linux 服务器和 Apache 的 commons 的 FTP 客户端 API。
Any debugging tips and tricks will be helpful.
任何调试提示和技巧都会有所帮助。
Regards, Srinivas
问候, 斯里尼瓦斯
回答by Onkar Joshi
I too ran into this a while back.
不久前我也遇到了这个问题。
I noticed that if the file was bigger than a certain size (it was 174 bytes or so for me), it did get transferred correctly. Smaller files ended up being created as zero byte files.
我注意到如果文件大于某个大小(对我来说是 174 字节左右),它确实被正确传输。较小的文件最终被创建为零字节文件。
I believe it is a bug in the Apache commons ftp code. I fixed it by getting the source and did a quick fix and the resulting jar that I built worked for us.
我相信这是 Apache commons ftp 代码中的一个错误。我通过获取源代码修复了它并进行了快速修复,我构建的最终 jar 为我们工作。
If I remember the fix right, I disabled Nagle's algorithm with socket.setTcpNoDelay(false) on the socket that was being used for the transfer in the commons ftp code.
如果我没记错的话,我在公共 ftp 代码中用于传输的套接字上使用 socket.setTcpNoDelay(false) 禁用了 Nagle 的算法。
回答by jomofrodo
Another possible firewall config issue: If you are ftp'ing from a linux/unix box with iptables configured, make sure that you have the tables configured to allow ftp "connection tracking".
另一个可能的防火墙配置问题:如果您从配置了 iptables 的 linux/unix 机器进行 ftp,请确保您将表配置为允许 ftp“连接跟踪”。
In the course of the ftp transaction, your client machine establishes the ftp connection, then issues the ftp STOR command to upload the file. The initial part of the transaction takes place on the standard ftp sockets (20,21), then switches to a random high-numbered port selected by the ftp server if in ACTIVE mode, or by the client if in PASSIVE (PASV) mode. If you are in ACTIVE mode iptables may not allow the server to communicate with your client machine on this randomly selected port, you will get a zero-byte file with the correct name and no other data.
在ftp事务过程中,您的客户端机器建立ftp连接,然后发出ftp STOR命令上传文件。事务的初始部分发生在标准 ftp 套接字 (20,21) 上,然后切换到由 ftp 服务器(如果处于 ACTIVE 模式)或客户端(如果处于 PASSIVE (PASV) 模式)选择的随机高编号端口。如果您处于 ACTIVE 模式,iptables 可能不允许服务器在这个随机选择的端口上与您的客户端机器通信,您将获得一个具有正确名称且没有其他数据的零字节文件。
You can fix this by switching the transaction to PASSIVE mode from the client side, or by setting iptables on the client machine to do "connection tracking":
您可以通过从客户端将事务切换到 PASSIVE 模式来解决此问题,或者通过在客户端计算机上设置 iptables 来执行“连接跟踪”:
http://www.linuxchix.org/content/courses/security/connection_tracking
http://www.linuxchix.org/content/courses/security/connection_tracking
回答by Tharanga
Check your disk capacity. I faced to this kind of situation when I was working on Raspberry Pi project. I had to work with large files downloads and it caused to fill-up RPi's SD card very quickly. After reaching some extent FTP uploads 0 bytes files. Not only for small storage, this can be happened anywhere. For example, your server can create gigabytes of error log files. After sometime your server space will be filled by those log files. Again same thing happens on FTP uploads. Check that out too. Cheers!
检查您的磁盘容量。我在做树莓派项目的时候就遇到过这种情况。我不得不处理大文件下载,这导致 RPi 的 SD 卡很快被填满。达到一定程度后,FTP 上传 0 字节文件。不仅对于小型存储,这可能发生在任何地方。例如,您的服务器可以创建千兆字节的错误日志文件。一段时间后,您的服务器空间将被这些日志文件填满。同样的事情发生在 FTP 上传上。也检查一下。干杯!
回答by nikudesu
If it happens sometimes, it smells like a firewall configuration on one of the ends. Hard to diagnose, but start (if you can) try switching between active/passive.
如果它有时发生,它闻起来像一端的防火墙配置。很难诊断,但开始(如果可以的话)尝试在主动/被动之间切换。
Look here for a better reference: http://slacksite.com/other/ftp.html
在这里查看更好的参考:http: //slacksite.com/other/ftp.html
回答by the.jxc
Try running WireShark and see what is going across the wire? That might give you a clue as to where the problem lies.
尝试运行 WireShark,看看网络上发生了什么?这可能会为您提供有关问题所在的线索。

