Ejemplo n.º 1
0
        public async Task<FtpResponse> CloseDataStreamAsync(StreamChannel channel)
        {
            var finalResponse = await m_Stream.GetReplyAsync<FtpResponse>();

            return finalResponse;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Connect to the server
        /// </summary>
        public async Task ConnectAsync()
        {
            if (m_Stream == null)
            {
                m_Stream = new StreamChannel();
            }
            else
            {
                if (IsConnected) await DisconnectAsync();
            }

            if (HostName == null)
                throw new FtpException("No host has been specified");

            if (Credentials == null)
                throw new FtpException("No credentials have been specified");

            FtpResponse reply;

            if (await m_Stream.ConnectAsync(HostName, ServiceName))
            {
                if (!(reply = await GetReplyAsync()).Success)
                {
                    if (reply.Code == null)
                    {
                        throw new IOException("The connection was terminated before a greeting could be read.");
                    }

                    throw new FtpCommandException(reply);
                }
            }

            // TODO: If the encryption mode is set to explicit, raise to SSL

            if (Credentials != null)
            {
                await AuthenticateAsync(Credentials);
            }

            if ((reply = await m_Stream.GetFeaturesAsync()).Success)
                m_Caps = ((FtpFeaturesResponse) reply).Features;

            // Enable UTF8 if it's available
            if (m_Caps.HasFlag(FtpCapability.UTF8))
            {
                // If the server supports UTF8 it should already be enabled and this
                // command should not matter however there are conflicting drafts
                // about this so we'll just execute it to be safe. 
                await m_Stream.SetOptionsAsync("UTF8 ON");
                m_Stream.Encoding = Encoding.UTF8;
            }
        }