Apache commons-net FTP - 将文件上传到安全 FTP IIS
我正在尝试使用 Apache commons-net FTP 库将大文件(>100Mb)上传到安全 FTP 服务器 IIS。
这是我的代码:
try{
ftpClient = new FTPSClient("TLS", false);
this.ftpClient.setDataTimeout(6000000);
this.ftpClient.setConnectTimeout(6000000);
ftpClient.connect(host, port);
ftpClient.login(userName, password);
ftpClient.enterLocalPassiveMode();
if (ftpClient.getReplyCode() == 230){
ftpClient.sendCommand("OPTS UTF8 ON");
ftpClient.execPBSZ(0);
ftpClient.execPROT("P");
else{
throw new Exception("connection failed.....");}
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
InputStream is= new FileInputStream("C:\\movie.avi");
ftpClient.setUseEPSVwithIPv4(true);
ftpClient.storeFile(remotePath, is);
is.close();
}
catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
无法上传大于 19Mb 的文件。 storeFile 方法抛出 IOException 且 StackTrace 为空。您可以看到下面的IOException
变量:
e CopyStreamException (id=39)
cause CopyStreamException (id=39)
detailMessage "IOException caught while copying." (id=45)
ioException SocketException (id=46)
cause SocketException (id=46)
detailMessage "Connection reset by peer: socket write error" (id=50)
stackTrace null
stackTrace null
totalBytesTransferred 19084288
实际上它的行为方式如下:
1)当我开始上传时,创建了零大小的文件,而我上传文件大小仍然为零并且发生异常时,这个空文件被 FTP 删除。
2)有趣的是,FileZila 也无法上传这些文件,但其大小限制为 70Mb。
我错过了什么吗?
I'm trying to upload large file (>100Mb) using Apache commons-net FTP library to Secure FTP Server IIS.
Here is my code:
try{
ftpClient = new FTPSClient("TLS", false);
this.ftpClient.setDataTimeout(6000000);
this.ftpClient.setConnectTimeout(6000000);
ftpClient.connect(host, port);
ftpClient.login(userName, password);
ftpClient.enterLocalPassiveMode();
if (ftpClient.getReplyCode() == 230){
ftpClient.sendCommand("OPTS UTF8 ON");
ftpClient.execPBSZ(0);
ftpClient.execPROT("P");
else{
throw new Exception("connection failed.....");}
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
InputStream is= new FileInputStream("C:\\movie.avi");
ftpClient.setUseEPSVwithIPv4(true);
ftpClient.storeFile(remotePath, is);
is.close();
}
catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
It fails to upload files larger then 19Mb. storeFile methods throws IOException
with empty StackTrace. You can see below IOException
variables:
e CopyStreamException (id=39)
cause CopyStreamException (id=39)
detailMessage "IOException caught while copying." (id=45)
ioException SocketException (id=46)
cause SocketException (id=46)
detailMessage "Connection reset by peer: socket write error" (id=50)
stackTrace null
stackTrace null
totalBytesTransferred 19084288
Actually it behaves the following way:
1) when I'm starting upload, zero size file created, while I'm uploading file size is still zero and when the exception occurs, this empty file removed by FTP.
2) funny thing is that FileZila fails to upload these files as well, but its limit size is 70Mb.
Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出色地。令人遗憾的是,这个问题是由防火墙引起的,它在 5 分钟超时后关闭了数据端口。
Well. Sad by true, the problem caused by firewall, which closed Data port after 5 minutes time out.