我正在使用FTPClient在其中一台服务器上执行FTP。我能够获得所有文件列表,但当我尝试读取这些文件时,它显示“连接已关闭”,“连接被拒绝”,“连接重置”异常。我正在使用以下代码进行FTP
FTPClient client = new FTPClient();
client.connect("IpAddress");
client.login("Username", "Password");
client.setRemoteVerificationEnabled(false);
client.enterLocalPassiveMode();
FTPFile[] files = client.listFiles(dirPath);
上面的代码是我所有的文件名然后我在我的搜索对象中传递这些名称。在那里我使用相同的“客户端”对象
InputStream in = client.retrieveFileStream("filename with path as a string");
try(BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
while (null != reader && (line = reader.readLine()) != null) {
if (null != line && line.contains(wordToSearch)) {
System.out.println("word Found");
}
}
该文件夹包含太多文件。我能够获取所有文件,为什么它在读取时失败。
例外是:
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
22:57:22,594 INFO Connector:38 - Traversing and Searching Finished......
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:894)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:759)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3293)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3271)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2930)
at com.novigolabs.connectors.FtpConnector.listFiles(FtpConnector.java:44)
at com.novigolabs.connectors.FtpConnector.listFiles(FtpConnector.java:55)
at com.novigolabs.search.Traverse.initiateSearch(Traverse.java:117)
at com.novigolabs.search.Traverse.run(Traverse.java:45)
at java.lang.Thread.run(Thread.java:724)