Class used to connect to an FTP/FTPS server. The main goal of this class is to provide a complete and easy to use FTP client connection, implementing SSL/TLS extension and providing tested compatibility to the main FTP server products. Implemented RFCs: 959, 2228, 2389, 2428, 2640, 3659, 4217. Not all commands described in the above RFCs are implemented at the current stage.
Requirements: MS Framework 2.0 and above or Mono 2.0 and above.
상속: IDisposable
예제 #1
0
 public void Set(string id, FtpsClient client)
 {
     if (_ftpClients.ContainsKey(id))
     {
         _ftpClients[id] = client;
     }
     else
     {
         if (_ftpClients.Count == 0)
         {
             // dispose of the ftp on shutdown
             Plug.OnShutDown += DisconnectFtp;
         }
         _ftpClients.Add(id, client);
     }
 }
예제 #2
0
파일: FtpPackager.cs 프로젝트: massreuy/3P
        /// <summary>
        /// Connects to a FTP server trying every methods
        /// </summary>
        private void ConnectFtp(FtpsClient ftp, string userName, string passWord, string server, int port)
        {
            NetworkCredential credential = null;

            if (!string.IsNullOrEmpty(userName))
            {
                credential = new NetworkCredential(userName, passWord);
            }

            var modes = new List <EsslSupportMode>();

            typeof(EsslSupportMode).ForEach <EsslSupportMode>((s, l) => { modes.Add((EsslSupportMode)l); });

            ftp.DataConnectionMode = EDataConnectionMode.Passive;
            while (!ftp.Connected && ftp.DataConnectionMode == EDataConnectionMode.Passive)
            {
                foreach (var mode in modes.OrderByDescending(mode => mode))
                {
                    try {
                        var curPort = port > -1 ? port : ((mode & EsslSupportMode.Implicit) == EsslSupportMode.Implicit ? 990 : 21);
                        ftp.Connect(server, curPort, credential, mode, 1800);
                        ftp.Connected = true;
                        break;
                    } catch (Exception) {
                        //ignored
                    }
                }
                ftp.DataConnectionMode = EDataConnectionMode.Active;
            }

            // failed?
            if (!ftp.Connected)
            {
                throw new Exception("Failed to connect to a FTP server with : " + string.Format(@"Username : {0}, Password : {1}, Host : {2}, Port : {3}", userName ?? "none", passWord ?? "none", server, port == -1 ? 21 : port));
            }
        }