我在用commons-net包处理ftp时,在一个循环中调用
ftp.listFiles()
返回当前目录下的所有文件。
奇怪的是程序第一次调用
ftp.listFiles()
返回了正确的文件列表,可是后面返回的数组长度都为0,但是目录下确实是有文件的,十分不解...
问题补充:先谢谢 congjl2002 的回答,我没有执行logout(); 或disconnect();
public InputStream checkResponse(FtpSynInfo synInfo) throws IOException{
boolean boo = false;
InputStream input = null;
String respFileName = synInfo.getFileName().trim()+RESP;
boo = ftp.isFileExist(synInfo.getFilePath(),respFileName);
if(boo){
//log.debug("获取输入流....");
input = ftp.downFile(respFileName);
log.debug("获取输入流...."+input);
}
//}
return input;
}
这个方法是在循环中执行的,登陆在循环的前面执行,登出在循环的后面执行。
ftp.isFileExist()方法中调用了我上面说的ftp.listFiles() 。
现在发现 去掉这句input = ftp.downFile(respFileName);就可以了。不知为什么。
input我在外面的方法中关闭了。
问题补充:问题解决了,不能脱离文档啊。
以下是retrieveFileStream方法的说明:
“ You must close the InputStream when you finish reading from it. The InputStream itself will take care of closing the parent data connection socket upon being closed. To finalize the file transfer you must call completePendingCommand and check its return value to verify success. ”
只要在关闭流 input.close()后面加上一句
ftpClient.completePendingCommand();
就搞定了!
相关推荐
在这个特定的案例中,我们关注的是`commons-net-ftp-2.0.jar.zip`这个压缩包,它包含了Apache Commons Net FTP库的2.0版本。这个库对于Java开发者来说,是进行FTP文件传输的重要工具。 FTP是一种用于在互联网上传输...
c3p0依赖包mchange-commons-java-0.2.19.jar; 特别说明:c3p0(c3p0-0.9.5.5.bin.tgz)的lib包里面含此mchange-commons-java-0.2.19.jar文件。
赠送jar包:commons-net-3.3.jar; 赠送原API文档:commons-net-3.3-javadoc.jar; 赠送源代码:commons-net-3.3-sources.jar; 赠送Maven依赖信息文件:commons-net-3.3.pom; 包含翻译后的API文档:commons-...
使用C3P0额外依赖的一个jar包 :mchange-commons-java-0.2.3.4.jar
赠送jar包:spring-data-commons-2.0.6.RELEASE.jar; 赠送原API文档:spring-data-commons-2.0.6.RELEASE-javadoc.jar; 赠送源代码:spring-data-commons-2.0.6.RELEASE-sources.jar; 赠送Maven依赖信息文件:...
hibernate-commons-annotations-5.1.0.Final.jar
赠送jar包:commons-net-3.1.jar; 赠送原API文档:commons-net-3.1-javadoc.jar; 赠送源代码:commons-net-3.1-sources.jar; 包含翻译后的API文档:commons-net-3.1-javadoc-API文档-中文(简体)版.zip 对应...
赠送jar包:spring-data-commons-2.3.9.RELEASE.jar; 赠送原API文档:spring-data-commons-2.3.9.RELEASE-javadoc.jar; 赠送源代码:spring-data-commons-2.3.9.RELEASE-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:commons-net-3.8.0.jar; 赠送原API文档:commons-net-3.8.0-javadoc.jar; 赠送源代码:commons-net-3.8.0-sources.jar; 赠送Maven依赖信息文件:commons-net-3.8.0.pom; 包含翻译后的API文档:...
在"commons-logging-1.2"这个子目录中,通常会包含以下组件: 1. `commons-logging-1.2.jar`: 这是主库文件,包含了Apache Commons Logging的所有接口和实现。 2. `commons-logging-api-1.2.jar`(可能包含):如果...
标题中的"asm-commons-2.2.1-sources.jar.zip"是一个压缩文件,它包含了ASM Commons库的源代码版本2.2.1。ASM Commons是ASM库的一个扩展,ASM是一个广泛使用的Java字节码操控和分析框架。ASM Commons提供了在ASM基础...
标题中的"commons-fileupload-1.3.3-bin.tar.gz"是一个压缩包文件,包含了Apache Commons FileUpload 1.3.3版本的二进制(bin)文件,通常包括JAR库和其他必要的资源。 Apache Commons FileUpload的工作原理是基于...
赠送jar包:commons-codec-1.9.jar; 赠送原API文档:commons-codec-1.9-javadoc.jar; 赠送源代码:commons-codec-1.9-sources.jar; 赠送Maven依赖信息文件:commons-codec-1.9.pom; 包含翻译后的API文档:...
赠送jar包:spring-data-commons-2.0.9.RELEASE.jar; 赠送原API文档:spring-data-commons-2.0.9.RELEASE-javadoc.jar; 赠送源代码:spring-data-commons-2.0.9.RELEASE-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:commons-net-3.6.jar; 赠送原API文档:commons-net-3.6-javadoc.jar; 赠送源代码:commons-net-3.6-sources.jar; 赠送Maven依赖信息文件:commons-net-3.6.pom; 包含翻译后的API文档:commons-...
赠送jar包:commons-fileupload-1.4.jar; 赠送原API文档:commons-fileupload-1.4-javadoc.jar; 赠送源代码:commons-fileupload-1.4-sources.jar; 赠送Maven依赖信息文件:commons-fileupload-1.4.pom; 包含...
使用"commons-collections-3.2.2-bin.zip"时,只需将解压后的jar文件添加到项目的类路径中,就可以直接调用其中的各种工具类和方法。当然,随着Java版本的更新,Apache Commons Collections也发布了更高版本,包含了...
赠送jar包:commons-collections4-4.1.jar; 赠送原API文档:commons-collections4-4.1-javadoc.jar; 赠送源代码:commons-collections4-4.1-sources.jar; 赠送Maven依赖信息文件:commons-collections4-4.1.pom;...