Beispiel #1
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     try
     {
         if (btnLogin.Text == "点击连接")
         {
             if (CheckUserInfo())
             {
                 string ipAddr   = this.toolStripTextBoxIpAddr.Text.Trim();
                 string port     = this.toolStripTextBoxPort.Text.Trim();
                 string userName = this.toolStripTextBoxName.Text.Trim();
                 string password = this.toolStripTextBoxPassword.Text.Trim();
                 ftpClient = new FTPClient(ipAddr, port, userName, password);
                 if (!ftpClient.Connect())
                 {
                     lblMsg.Text = "连接失败,请检查服务器状况";
                 }
                 else
                 {
                     if (ftpClient.Login())
                     {
                         lblMsg.Text   = "登录成功";
                         btnLogin.Text = "断开连接";
                         toolStripTextBoxIpAddr.ReadOnly   = true;
                         toolStripTextBoxName.ReadOnly     = true;
                         toolStripTextBoxPassword.ReadOnly = true;
                         toolStripTextBoxPort.ReadOnly     = true;
                         ShowFilesDirectory();
                     }
                     else
                     {
                         lblMsg.Text = "用户名/密码出错";
                         ftpClient.Close();
                     }
                 }
             }
         }
         else
         {
             ftpClient.Close();
             FTPflowLayoutPanel.Controls.Clear();
             btnLogin.Text = "点击连接";
             toolStripTextBoxIpAddr.ReadOnly   = false;
             toolStripTextBoxName.ReadOnly     = false;
             toolStripTextBoxPassword.ReadOnly = false;
             toolStripTextBoxPort.ReadOnly     = false;
             lblMsg.Text = "";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }