Example #1
0
        // ReSharper disable once ParameterHidesMember
        public void BeginSession(FtpConnectionData connectionData)
        {
            ftpChannel = ftpChannelFactory.CreateChannel();

            ftpChannel.Connect(connectionData.Host, connectionData.Port);
            ftpCommunicator.AttachToChannel(ftpChannel);

            FtpServerResponse response = ftpCommunicator.ReadResponse();

            if (response.ReturnCode != (int)FtpReturnCode.ServiceReadyForNewUser)
            {
                throw FtpException("Could not connect to the FTP server", response);
            }

            response = SendCommand("USER {0}", connectionData.Credentials.UserName);

            if (response.ReturnCode == (int)FtpReturnCode.UserNameOkNeedPassword)
            {
                response = SendCommand("PASS {0}", connectionData.Credentials.Password);
            }

            if (response.ReturnCode == (int)FtpReturnCode.UserLoggedIn)
            {
                SetBinaryMode();
                return;
            }

            throw FtpException("Could not log in to the FTP server", response);
        }
Example #2
0
 void IFtpSession.BeginSession(FtpConnectionData connectionData)
 {
     Contract.Requires(connectionData != null);
 }