Example #1
0
        public bool Connect(IFTPSettings settings)
        {
            var connectionInfo = new ConnectionInfo(settings.address,
                                                    settings.userName,
                                                    new PasswordAuthenticationMethod(settings.userName, settings.password)
                                                    );

            _client = new SftpClient(connectionInfo);
            _client.Connect();
            _directory = string.IsNullOrWhiteSpace(settings.directory) ? "." : settings.directory;
            return(true);
        }
Example #2
0
        public static IServerAccess CreateAccessTo(IFTPSettings settings)
        {
            switch (settings.protocol.ToLower())
            {
            case "ftp":
                return(new FTPAccess(settings));

            case "sftp":
                return(new SFTPAccess(settings));

            default:
                throw new ArgumentException($"Unknown protocol {settings.protocol}");
            }
        }
Example #3
0
        public bool Connect(IFTPSettings settings)
        {
            _client?.Disconnect();
            var addressPort       = settings.address.Split(':');
            int port              = 21;
            NetworkCredential nwc = null;

            if (addressPort.Length > 1)
            {
                port = Convert.ToInt32(addressPort[1]);
            }

            if (!string.IsNullOrEmpty(settings.userName) && settings.userName != "anonymous")
            {
                nwc = new NetworkCredential(settings.userName, settings.password);
            }

            _client = new FtpClient($"{addressPort[0]}", port, nwc)
            {
                DataConnectionType = (settings.mode.ToLower() == "active")
                    ? FtpDataConnectionType.AutoActive
                    : FtpDataConnectionType.AutoPassive,
            };
            if (settings.encryption != DestinationFTP.EncryptionNone)
            {
                if (settings.encryption == DestinationFTP.EncryptionSSL)
                {
                    _client.EncryptionMode = FtpEncryptionMode.Implicit;
                }
                else
                {
                    _client.EncryptionMode = FtpEncryptionMode.Explicit;
                }
            }

            _client.Connect();
            _client.SetWorkingDirectory(settings.directory);
            return(true);
        }
Example #4
0
 public FTPAccess(IFTPSettings settings)
 {
     Connect(settings);
 }