Java Code Examples for org.apache.commons.net.ftp.FTPClient#setSoTimeout()

The following examples show how to use org.apache.commons.net.ftp.FTPClient#setSoTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FTPClientTemplate.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/** 
 * 返回一个FTPClient实例 
 *  
 * @throws Exception
 */  
private FTPClient getFTPClient()throws Exception {
    if (ftpClientThreadLocal.get() != null && ftpClientThreadLocal.get().isConnected()) {  
        return ftpClientThreadLocal.get();  
    } else {  
        FTPClient ftpClient = new FTPClient(); //构造一个FtpClient实例
        ftpClient.setControlEncoding(encoding); //设置字符集  
  
        connect(ftpClient); //连接到ftp服务器  
  
        //设置为passive模式  
        if (passiveMode) {  
            ftpClient.enterLocalPassiveMode();  
            String replystr=ftpClient.getReplyString();
            ftpClient.sendCommand("PASV");
            replystr=ftpClient.getReplyString();
        }  
        setFileType(ftpClient); //设置文件传输类型  
  
        try {  
            ftpClient.setSoTimeout(clientTimeout);  
            ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
        } catch (SocketException e) {
            throw new Exception("Set timeout error.", e);
        }  
        ftpClientThreadLocal.set(ftpClient);  
        return ftpClient;  
    }  
}