Commons-net FTPClient completePendingCommand()经常使程序死掉的原因分析以及解决方式
来源:互联网 发布:java覆盖例子 编辑:程序博客网 时间:2024/05/24 00:34
commons-net的FTPClient,在使用public InputStream retrieveFileStream(String remote)
方法时需要特别注意,在调用这个接口后,一定要手动close掉返回的InputStream,然后再调用completePendingCommand方法,若不是按照这个顺序,则不对,伪代码:
- InputStream is = ftpClient.retrieveFileStream(remote);
- is.close();
- ftpClient.completePendingCommand();
retrieveFileStream的API文档说的有点罗嗦,还可以使用下列方法来替换上述使用方式
使用一个中间文件来做一个转接,这种方式比上述方法的好处就是自己容易控制,不容易出问题。伪代码如下:
- File localFile = new File(localPath, localFileName);
- OutputStream output = new FileOutputStream(localFile);
- ftpClient.retrieveFile(remoteFileName, output);
- output.close();
- InputStream input = new FileInputStream(localFile);
简单来说:completePendingCommand()会一直在等FTP Server返回226 Transfer complete,但是FTP Server只有在接受到InputStream执行close方法时,才会返回。所以先要执行close方法
0 0
- Commons-net FTPClient completePendingCommand()经常使程序死掉的原因分析以及解决方式
- Commons-net FTPClient completePendingCommand()经常使程序死掉的原因分析以及解决方式
- WCF服务最近经常死掉的原因分析总结
- Commons-net FTPClient上传下载的封装
- Commons-net FTPClient上传下载的封装
- ftpClient(apache提供的commons-net-3.3)
- 关于win2003server下iis经常死掉的原因
- apache FTPClient replyCode 421,FTPConnectionClose 问题原因以及解决
- 关于FTPClient(Apache的commons.net包下的)研究
- Jakarta Commons NET(FTPClient)的简单示例
- Jakarta Commons NET(FTPClient)的简单示例
- 让Apache的commons-net-3.3中的FTPClient支持中文
- 让Apache的commons-net-3.3中的FTPClient支持中文
- 多线程-线程安全问题的产生原因分析以及同步代码块的方式解决线程安全问题
- OpenSSL.Net 在生产环境中无法正常加载的原因分析与解决方式。
- 解决mysql连接过多和死掉以及拒绝服务的方法
- org.apache.commons.net.ftp.FTPClient使用
- org.apache.commons.net.ftp.FTPClient 例子
- .NET ASP 性能优化技巧(26个)
- C语言-不同类型数据间的混合运算
- 1009--Java自定义注解 Annotation详解
- Tomcat优化
- 解决jquery操作checkbox全选全不选无法勾选问题
- Commons-net FTPClient completePendingCommand()经常使程序死掉的原因分析以及解决方式
- whoami: cannot find name for user ID xxxx
- POJ 1163 The Triangle
- android JNI之 'GetObjectClass' in something not a structure or union
- A - Decoding Baby Boos---(2015 NEUQ_ACM summer training #1)
- HDU 4496 D-City
- Light, more light
- 大讲台分享:关于Hive常见的问题及解决方案(一)
- n个骰子的点数