zoukankan      html  css  js  c++  java
  • ftpClient的连接超时设置

    FTPClient ftpClient = new FTPClient();
     ftpClient.setConnectTimeout(10*1000); // 10s,如果超过就判定超时了
     ftpClient.connect(hostName, 21);

    http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/SocketClient.html#setConnectTimeout(int)

    Class org.apache.commons.net.SocketClient
    void setConnectTimeout(int connectTimeout)
    Sets the connection timeout in milliseconds, which will be passed to the Socket object's connect() method.
     1 /**
     2      * 登录FTP服务器
     3      * 
     4      * @param host
     5      *            FTP主机地址
     6      * @param port
     7      *            FTP主机端口
     8      * @param username
     9      *            用户名
    10      * @param password
    11      *            密码
    12      * @throws Exception
    13      *             登录失败
    14      */
    15     public void ftpLogin(String host, int port, String username, String password)
    16             throws Exception {
    17         client = new FTPClient();
    18         // 设定连接超时时间
    19         client.setConnectTimeout(10*1000);
    20         try {
    21             client.connect(host, port);
    22             client.login(username, password);
    23             replyCode = client.getReplyCode();
    24             if (!FTPReply.isPositiveCompletion(replyCode)) {
    25                 reply = client.getReplyString().trim();
    26                 throw new Exception("FTP 登录失败,响应消息:" + reply);
    27             }
    28             log.info("FTP 登录成功");
    29 
    30             // 设置缓冲区
    31             client.setBufferSize(BufferSize);
    32             // 设置传输模式
    33             // client.setFileType(FTP.BINARY_FILE_TYPE);
    34         } catch (Exception e) {
    35             log.error(e.getMessage(), e);
    36             throw new Exception("FTP 登录失败");
    37         }
    38     }
  • 相关阅读:
    CF1324F Maximum White Subtree——换根dp
    bzoj3029 守卫者的挑战
    k8s-pod
    k8s 介绍
    docker-dockerfile
    docker学习
    git
    windows 上git安装及gitlab 连接
    gitlab 配置管理
    gitlab安装/配置/维护
  • 原文地址:https://www.cnblogs.com/ihongyan/p/4104687.html
Copyright © 2011-2022 走看看