Exemplo n.º 1
0
        private async Task <Stream> setupDataStreamAsync(bool isRead)
        {
            if (secureConnection)
            {
                DataStream = await SslClient.ConnectAsync(DataStream, Host);
            }
            if (isMODEZ)
            {
                DataStream = setDeflateStream(DataStream, isRead);
            }

            return(DataStream);
        }
Exemplo n.º 2
0
        private async Task <Stream> setupDataStreamAsync(bool isRead)
        {
            if (secureConnection)
            {
                if (Encryption.Protocol == FTPSslProtocol.TLS)
                {
                    DataStream = await SslClient.ConnectAsync(DataStream, Host, SslProtocols.Tls12);
                }
                else
                {
                    DataStream = await SslClient.ConnectAsync(DataStream, Host, SslProtocols.Ssl3);
                }
            }

            if (isMODEZ)
            {
                DataStream = setDeflateStream(DataStream, isRead);
            }

            return(DataStream);
        }
Exemplo n.º 3
0
        internal override async Task <bool> ConnectAsync(bool reconnect = false, bool tryReconnect = true)
        {
            if (UserName.NullEmpty())
            {
                UserName = "******";
            }
            if (Password.NullEmpty())
            {
                Password = CryptoHashing.Encrypt("*****@*****.**");
            }
            if (Port == 0)
            {
                Port = 21;
            }

            Connecting();
            if (reconnect)
            {
                closeConnection();
                closeDataConnection();
                InfoMessage("Connection Dropped! Reconnecting...", MessageType.Info);
            }
            else
            {
                InfoMessage("Connecting to " + Host + ":" + Port.ToString(), MessageType.Info);
            }

            secureConnection = (Encryption.Type == EncryptionType.ImplicitType);
            ControlSocket    = await createStreamAsync(Host, Port);

            if ((ControlSocket == null) && tryReconnect)
            {
                for (int i = 1; i < RETRY_TIMES; i++)
                {
                    if (IsCanceled)
                    {
                        return(false);
                    }

                    InfoMessage("Reconnecting after " + (5 * i) + " seconds...{" + (RETRY_TIMES - i) + "}", MessageType.Info);
                    await Task.Delay(i * 5000);

                    ControlSocket = await createStreamAsync(Host, Port);

                    if (ControlSocket != null)
                    {
                        break;
                    }
                }
            }

            if (ControlSocket != null)
            {
                ControlStream = new NetworkStream(ControlSocket);
                if (secureConnection)
                {
                    if (Encryption.Protocol == FTPSslProtocol.TLS)
                    {
                        ControlStream = await SslClient.ConnectAsync(ControlStream, Host, SslProtocols.Tls12);
                    }
                    else
                    {
                        ControlStream = await SslClient.ConnectAsync(ControlStream, Host, SslProtocols.Ssl3);
                    }
                }
                IsConnected = (ControlStream != null);
            }

            IsConnected = ((ControlStream != null) && (await getResponseAsync() == 220));

            if (IsConnected && (Encryption.Type == EncryptionType.ExplicitType))
            {
                IsConnected = false;
                string protocol = "TLS";
                if (Encryption.Protocol == FTPSslProtocol.SSL)
                {
                    protocol = "SSL";
                }

                if (await _commandAuthAsync(protocol))
                {
                    if (Encryption.Protocol == FTPSslProtocol.TLS)
                    {
                        ControlStream = await SslClient.ConnectAsync(ControlStream, Host, SslProtocols.Tls12);
                    }
                    else
                    {
                        ControlStream = await SslClient.ConnectAsync(ControlStream, Host, SslProtocols.Ssl3);
                    }
                    secureConnection = IsConnected = (ControlStream != null);
                }
            }

            if (!IsConnected || !(await _logInAsync()))
            {
                await _failedToConnectAsync();

                return(false);
            }

            if (secureConnection)
            {
                InfoMessage("Secure Connection Established.", MessageType.Info);
            }
            else
            {
                InfoMessage("Connection Established.", MessageType.Info);
            }

            await _afterConnectAsync();

            Connected();
            return(true);
        }