我正在从Apache库(commons.net ver 3.2)的帮助下从服务器下载ftp文件.下载很好,我收到了我需要的所有文件,并将它们保存在一个文件夹中.我遇到的问题是超时,因为当我下载时连接中断时我需要一条错误消息,告诉我连接已经丢失,但我发现这样做很困难,我搜索了无数的论坛,包括这个一个,我已经尝试了很多方法来解决这个问题,但还没有人有结果!我的代码如下:
public void doSomething(String ip, int port, String user, String pass, String server, String remotePath, String localPath) {
int tenseconds = 10 * 1000;
int thirtyseconds = 30 * 3000;
Socket s4 = new Socket();
java.net.InetSocketAddress adr = new java.net.InetSocketAddress("213.0.17.234", 21);
s4.connect(adr, thirtyseconds);
FTPClient client = new FTPClient();
org.apache.commons.vfs2.FileSystemOptions fileSystemOptions = null;
String key = FtpFileSystemConfigBuilder.getInstance().getEntryParser(fileSystemOptions);
try {
client.setConnectTimeout(tenseconds);
client.setDefaultTimeout(thirtyseconds);
client.connect(ip, port);
client.setSoTimeout(thirtyseconds);
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
throw new FileSystemException("vfs.provider.ftp/connect-rejected.error");
}
client.enterLocalPassiveMode();
boolean login = …Run Code Online (Sandbox Code Playgroud)