本文介绍了下议院FTPClient上传大文件后挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache FTPClient 3.1做了一个简单的文件上传。
storefile()工作正常尺寸较小的文件(小于100MB),但是当我尝试上传超过100MB的东西时,它会完成上传,但只是挂。

I'm using Apache Commons FTPClient 3.1 to do a simple file upload.storefile() works fine for files of smaller sizes (under 100MB), but when I try uploading something greater than 100MB, it would finish uploading but just hang.

我试图进入其他人一样被动模式建议,但它似乎并没有解决问题。我试过多个FTP服务器具有相同的结果,所以我猜它不是主机。

I've tried entering passive mode like others have suggested, but it doesn't seem to fix the problem. I've tried multiple FTP servers with the same results, so I'm guessing it's not the host.

下面是我在做什么的要点是:

Here's the gist of what I'm doing:

ftpClient.connect(...);
ftpClient.login(...);
ftpClient.enterLocalPassiveMode();
boolean success = ftpClient.storeFile(...);
if(success)
...

程序挂起的大文件第4行,但并成功上传的文件。

The program hangs at line 4 for large files, but does successfully upload the file.

推荐答案

http://commons.apache.org/net/api-3.1/org/apache/commons/net/ftp/FTPClient.html

其超时。此链接可能会有帮助。

Its timing out. This link may help.

控制通道保持活动的特点:
在文件传输,数据连接忙,但控制连接处于空闲状态。的FTP服务器知道该控制连接是在使用,所以通过缺乏活动不会关闭它,但它的很多更难网络路由器知道,控制和数据连接都彼此相关联。一些路​​由器可将该控制连接为空闲,并且如果传输通过数据连接需要比允许的空闲时间为路由器更长断开。
一种解决方法是通过控制连接发送一个安全指令(即NOOP)重置路由器的空闲计时器。这是启用如下:

Control channel keep-alive feature:During file transfers, the data connection is busy, but the control connection is idle. FTP servers know that the control connection is in use, so won't close it through lack of activity, but it's a lot harder for network routers to know that the control and data connections are associated with each other. Some routers may treat the control connection as idle, and disconnect it if the transfer over the data connection takes longer than the allowable idle time for the router.One solution to this is to send a safe command (i.e. NOOP) over the control connection to reset the router's idle timer. This is enabled as follows:

 ftpClient.setControlKeepAliveTimeout(300); // set timeout to 5 minutes

这将导致文件上传/下载的方法来发送NOOP大约每5分钟。

This will cause the file upload/download methods to send a NOOP approximately every 5 minutes.

这篇关于下议院FTPClient上传大文件后挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:45
查看更多