首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

ftp 联接

2012-12-19 
ftp 连接import java.io.*import java.net.*import sun.net.ftp.FtpClientclass CustomFtpClient exten

ftp 连接

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");        }    }}

热点排行