Beispiel #1
0
        private async Task OpenDataConnection()
        {
            if (ClientDataConnection != null && ClientDataConnection.IsConnectionOpen)
            {
                SendResponse(new FtpReply()
                {
                    ReplyCode = FtpReplyCode.TransferStarting, Message = "Transfer is starting."
                }, false);
                return;
            }

            SendResponse(new FtpReply()
            {
                ReplyCode = FtpReplyCode.AboutToOpenDataConnection, Message = "Trying to open data connection."
            }, false);

            switch (UserConnectionType)
            {
            case ConnectionType.ACTIVE:
            {
                ClientDataConnection.OpenActiveConnection();
                break;
            }

            case ConnectionType.EXT_PASSIVE:
            case ConnectionType.PASSIVE:
            {
                ClientDataConnection.OpenPassiveConnection();
                break;
            }
            }
        }
Beispiel #2
0
        public async Task OnSendData(Stream listingStream)
        {
            await OpenDataConnection().ConfigureAwait(false);

            await ClientDataConnection.SendBytes(listingStream);

            ClientDataConnection.Disconnect();
        }
Beispiel #3
0
        public async Task OnUploadFile(string parameter)
        {
            await OpenDataConnection();

            await ClientDataConnection.ReceiveBytes(parameter);

            ClientDataConnection.Disconnect();
        }
Beispiel #4
0
        public async Task OnDataChannelEncryptionDisabled()
        {
            ClientDataConnection.DisableEncryption();

            ActionsTracker.ConnectionSecurityChanged(null, new ConnectionSecurityChangedEventArgs()
            {
                EndPoint = ClientInitialRemoteEndPoint,
                Security = ConnectionFlags.HasFlag(ControlConnectionFlags.UsingTLSorSSL)
                ? ConnectionSecurity.ControlConnectionSecured
                : ConnectionSecurity.NonSecure
            });
        }
Beispiel #5
0
        public void OnEnterActiveMode(string endPoint)
        {
            // Example of a command : PORT 127,0,0,1,203,175
            var endPointBytes = endPoint.Split(',');
            var portBytes     = new byte[2] {
                byte.Parse(endPointBytes[4]), byte.Parse(endPointBytes[5])
            };

            ClientDataConnection.InitializeActiveConnection(portBytes[0] * 256 + portBytes[1],
                                                            new IPEndPoint(
                                                                IPAddress.Parse($"{endPointBytes[0]}.{endPointBytes[1]}.{endPointBytes[2]}.{endPointBytes[3]}")
                                                                , 0));

            UserConnectionType = ConnectionType.ACTIVE;
        }
Beispiel #6
0
        public string OnEnterPassiveMode()
        {
            var listeningPort = ClientDataConnection.InitializePassiveConnection();
            //send IP of server cuz by sending local ip client won't be able to connect
            var addressBytes = IPAddress.Parse(DefaultServerValues.ServerExternalIP).GetAddressBytes();

            UserConnectionType = ConnectionType.PASSIVE;

            return(string.Format(
                       "Entering Passive Mode ({0},{1},{2},{3},{4},{5})",
                       addressBytes[0],
                       addressBytes[1],
                       addressBytes[2],
                       addressBytes[3],
                       (byte)(listeningPort / 256),
                       listeningPort % 256));
        }
Beispiel #7
0
        public async Task OnDataChannelEncryptionEnabled()
        {
            if (!IsEncryptionSupported)
            {
                SendResponse(new FtpReply()
                {
                    ReplyCode = FtpReplyCode.NotImplemented, Message = "Server is not configured to support SSL/TLS."
                }, false);
                return;
            }

            ClientDataConnection.ActivateEncryption();

            ActionsTracker.ConnectionSecurityChanged(null, new ConnectionSecurityChangedEventArgs()
            {
                EndPoint = ClientInitialRemoteEndPoint,
                Security = ConnectionFlags.HasFlag(ControlConnectionFlags.UsingTLSorSSL)
                ? ConnectionSecurity.Both
                : ConnectionSecurity.DataChannelSecured
            });

            Logger.Log($"Enabled encryption for datachannel : {ClientInitialRemoteEndPoint.ToString()}"
                       , RecordKind.Status);
        }