[英]Apache FTPClient hangs during the retrieveFileStream
Dear all I have a problem with my code. 亲爱的所有我的代码有问题。 My ftp client is sometimes hanging when it is retrieving a file with "ftpClient.retrieveFileStream()".
使用“ ftpClient.retrieveFileStream()”检索文件时,我的ftp客户端有时会挂起。 Any idea what I can do?
知道我能做什么吗? I am using apache commons FTP client v3.4.
我正在使用apache commons FTP客户端v3.4。
increasing the buffer did not help 增加缓冲区没有帮助
ftpClient = new FTPClient(); ftpClient.setBufferSize(1024 * 1024); ftpClient.setConnectTimeout(10000); ftpClient.connect(serverAddress); ftpClient.login(userName,password); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); ftpClient.setSoTimeout(10000); log("retriving file " + remoteFilePath + "..."); OutputStream output = new FileOutputStream(localFilePath); InputStream inputStream = ftpClient.retrieveFileStream(remoteFilePath); // here it is sometimes hanging. try { IOUtils.copy(inputStream, output); output.flush(); } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(inputStream); ftpClient.completePendingCommand(); }
the last message I retrieve are looking usually like this: 我检索到的最后一条消息通常看起来像这样:
19:58:21.145 [main] INFO FTPDAO: retrieving file /Modell/5250/Artikel/25777/lg_keh68bgh_1.jpg...
19:58:21.145 [main] INFO Log4JFTPCommandListener - >> PASV
19:58:21.462 [main] INFO Log4JFTPCommandListener - << 227 Entering Passive Mode (195,216,65,165,168,240)
19:58:21.476 [main] INFO Log4JFTPCommandListener - >> RETR /Modell/5250/Artikel /25777/lg_keh68bgh_1.jpg
19:58:21.490 [main] INFO Log4JFTPCommandListener - << 150 Connection accepted
When I suspend the programm with the debugger, then it looks that is hanging at 当我用调试器挂起程序时,它看起来挂在了
java.net.SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int)
java.net.SocketInputStream.socketRead(FileDescriptor, byte[], int, int, int) line: 116
java.net.SocketInputStream.read(byte[], int, int, int) line: 170
java.net.SocketInputStream.read(byte[], int, int) line: 141
regards Mark 问候马克
I had this problem too. 我也有这个问题。 I changed
retrieveFileStream
to retrieveFile
. 我将
retrieveFileStream
更改为retrieveFile
。 and it doesn't hang there anymore. 而且它不再挂在那里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.