import java.io.*;
import java.net.*;
import sun.net.ftp.FtpClient;
class CustomFtpClient extends FtpClient {
public CustomFtpClient(String host) throws IOException {
super(host);
}
public CustomFtpClient(String host, int port) throws IOException {
super(host, port);
}
public CustomFtpClient() {
super();
}
public void setTimeout(int timeout) {
if (serverSocket != null) {
try {
serverSocket.setSoTimeout(timeout);
} catch (SocketException socketException) {
}
}
}
}
public class Test {
public static void main(String[] args) {
String host = "127.0.0.1";
String user = "username";
String password = "password";
try {
CustomFtpClient ftpClient = new CustomFtpClient();
ftpClient.openServer(host);
ftpClient.setTimeout(5000); // set timeout in 5 seconds
ftpClient.login(user, password);
ftpClient.binary();
ftpClient.closeServer();
System.out.println("Connect is OK");
} catch (Exception exp) {
exp.printStackTrace();
System.out.println("Connect is Timeout");
}
}
}
ftp 连接
最新推荐文章于 2024-06-19 09:17:24 发布