类似ftp类协议的登录是怎么做的?

实际上就是new Socket。因为Socket在的同时会去尝试连接远程服务器

 eg:

public String[] connect(String host, int port)
   throws IllegalStateException, IOException,
   FTPIllegalReplyException, FTPException {
  synchronized (lock) {
   // Is this client already connected to any host?
   if (connected) {
    throw new IllegalStateException("Client already connected to "
      + host + " on port " + port);
   }
   // Ok, it's connection time. Let's try!
   Socket connection = null;
   try {
    // Open the connection.
    connection = connector.connectForCommunicationChannel(host, port);
    if (security == SECURITY_FTPS) {
     connection = ssl(connection, host, port);
    }
    // Open the communication channel.
    communication = new FTPCommunicationChannel(connection, pickCharset());
    for (Iterator i = communicationListeners.iterator(); i.hasNext();) {
     communication.addCommunicationListener((FTPCommunicationListener) i.next());
    }
    // Welcome message.
    FTPReply wm = communication.readFTPReply();
    // Does this reply mean "ok"?
    if (!wm.isSuccessCode()) {
     // Mmmmm... it seems no!
     throw new FTPException(wm);
    }
    // Flag this object as connected to the remote host.
    this.connected = true;
    this.authenticated = false;
    this.parser = null;
    this.host = host;
    this.port = port;
    this.username = null;
    this.password = null;
    this.utf8Supported = false;
    this.restSupported = false;
    this.mlsdSupported = false;
    this.modezSupported = false;
    this.dataChannelEncrypted = false;
    // Returns the welcome message.
    return wm.getMessages();
   } catch (IOException e) {
    // D'oh!
    throw e;
   } finally {
    // If connection has failed...
    if (!connected) {
     if (connection != null) {
      // Close the connection, 'cause it should be open.
      try {
       connection.close();
      } catch (Throwable t) {
       ;
      }
     }
    }
   }
  }
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值