Example #1
0
        private void serverSocket_OnCommandReceived(ITftpCommand command, EndPoint endpoint)
        {
            //Ignore all other commands
            if (!(command is ReadOrWriteRequest))
            {
                return;
            }

            //Open a connection to the client
            ITransferChannel channel = TransferChannelFactory.CreateConnection(endpoint, new IPEndPoint(localInterface, 0));

            //Create a wrapper for the transfer request
            ReadOrWriteRequest request  = (ReadOrWriteRequest)command;
            ITftpTransfer      transfer = request is ReadRequest ? (ITftpTransfer) new LocalReadTransfer(channel, request.Filename, request.Options) : new LocalWriteTransfer(channel, request.Filename, request.Options);

            if (command is ReadRequest)
            {
                RaiseOnReadRequest(transfer, endpoint);
            }
            else if (command is WriteRequest)
            {
                RaiseOnWriteRequest(transfer, endpoint);
            }
            else
            {
                throw new Exception("Unexpected tftp transfer request: " + command);
            }
        }
Example #2
0
        private void ServerSocket_OnCommandReceived(ITFtpCommand command, EndPoint endpoint)
        {
            // Ignore all other commands
            if (!(command is ReadOrWriteRequest))
            {
                return;
            }

            // Open a connection to the client
            ITransferChannel channel = TransferChannelFactory.CreateConnection(endpoint);

            // Create a wrapper for the transfer request
            ReadOrWriteRequest request  = (ReadOrWriteRequest)command;
            ITFtpTransfer      transfer = request is ReadRequest ? (ITFtpTransfer) new LocalReadTransfer(channel, request.Filename, request.Options) : new LocalWriteTransfer(channel, request.Filename, request.Options);

            switch (command)
            {
            case ReadRequest _:
                RaiseOnReadRequest(transfer, endpoint);
                break;

            case WriteRequest _:
                RaiseOnWriteRequest(transfer, endpoint);
                break;

            default:
                throw new Exception($"Unexpected TFTP transfer request: {command}");
            }
        }
Example #3
0
        public TftpServer(IPEndPoint localAddress)
        {
            if (localAddress == null)
            {
                throw new ArgumentNullException("localAddress");
            }

            serverSocket = TransferChannelFactory.CreateServer(localAddress);
            serverSocket.OnCommandReceived += new TftpCommandHandler(serverSocket_OnCommandReceived);
            serverSocket.OnError           += new TftpChannelErrorHandler(serverSocket_OnError);
        }
Example #4
0
        public TFtpServer(IPEndPoint localAddress)
        {
            if (localAddress == null)
            {
                throw new ArgumentNullException(nameof(localAddress));
            }

            m_serverSocket = TransferChannelFactory.CreateServer(localAddress);
            m_serverSocket.OnCommandReceived += ServerSocket_OnCommandReceived;
            m_serverSocket.OnError           += ServerSocket_OnError;
        }
Example #5
0
        public TftpServer(IPEndPoint localAddress, TimeSpan timeout)
        {
            if (localAddress == null)
            {
                throw new ArgumentNullException("localAddress");
            }

            Timeout = (int)timeout.TotalMilliseconds;

            serverSocket = TransferChannelFactory.CreateServer(localAddress);
            serverSocket.OnCommandReceived += new TftpCommandHandler(serverSocket_OnCommandReceived);
            serverSocket.OnError           += new TftpChannelErrorHandler(serverSocket_OnError);
        }
Example #6
0
        /// <summary>
        /// PUT a file from the server.
        /// You have to call Start() on the returned ITFtpTransfer to start the transfer.
        /// </summary>
        public ITFtpTransfer Upload(string filename)
        {
            ITransferChannel channel = TransferChannelFactory.CreateConnection(m_remoteAddress);

            return(new RemoteWriteTransfer(channel, filename));
        }
Example #7
0
        /// <summary>
        /// GET a file from the server.
        /// You have to call Start() on the returned ITftpTransfer to start the transfer.
        /// </summary>
        public ITftpTransfer Download(String filename)
        {
            ITransferChannel channel = TransferChannelFactory.CreateConnection(remoteAddress);

            return(new RemoteReadTransfer(channel, filename));
        }
Example #8
0
        /// <summary>
        /// GET a file from the server via the specific local interface.
        /// You have to call Start() on the returned ITftpTransfer to start the transfer.
        /// </summary>
        public ITftpTransfer Download(String filename, IPAddress localInterface)
        {
            ITransferChannel channel = TransferChannelFactory.CreateConnection(remoteAddress, new IPEndPoint(localInterface, 0));

            return(new RemoteReadTransfer(channel, filename));
        }
Example #9
0
        /// <summary>
        /// PUT a file from the server.
        /// You have to call Start() on the returned ITftpTransfer to start the transfer.
        /// </summary>
        public ITftpTransfer Upload(String filename)
        {
            ITransferChannel channel = TransferChannelFactory.CreateConnection(remoteAddress, new IPEndPoint(IPAddress.Any, 0));

            return(new RemoteWriteTransfer(channel, filename));
        }