コード例 #1
0
ファイル: TftpServer.cs プロジェクト: vorot/tftp.net
        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);
            }
        }
コード例 #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}");
            }
        }
コード例 #3
0
ファイル: TftpServer.cs プロジェクト: pixey/tftp.net
        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);
        }
コード例 #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;
        }
コード例 #5
0
 public TFtpTransfer(ITransferChannel connection, string filename, ITransferState initialState)
 {
     ProposedOptions = TransferOptionSet.NewDefaultSet();
     Filename        = filename;
     RetryCount      = 5;
     SetState(initialState);
     Connection = connection;
     Connection.OnCommandReceived += Connection_OnCommandReceived;
     Connection.OnError           += Connection_OnError;
     Connection.Open();
     Timer = new Timer(Timer_OnTimer, null, 500, 500);
 }
コード例 #6
0
ファイル: TftpTransfer.cs プロジェクト: ericlee-code/tftp.net
 public TftpTransfer(ITransferChannel connection, String filename, ITransferState initialState)
 {
     this.ProposedOptions = TransferOptionSet.NewDefaultSet();
     this.Filename        = filename;
     this.RetryCount      = 5;
     this.SetState(initialState);
     this.connection = connection;
     this.connection.OnCommandReceived += new TftpCommandHandler(connection_OnCommandReceived);
     this.connection.OnError           += new TftpChannelErrorHandler(connection_OnError);
     this.connection.Open();
     this.timer = new Timer(timer_OnTimer, null, 500, 500);
 }
コード例 #7
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);
        }
コード例 #8
0
ファイル: TFtpClient.cs プロジェクト: sotaria/gsf
        /// <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));
        }
コード例 #9
0
 public LocalReadTransfer(ITransferChannel connection, string filename, IEnumerable <TransferOption> options)
     : base(connection, filename, new StartIncomingRead(options))
 {
 }
コード例 #10
0
 public RemoteReadTransfer(ITransferChannel connection, string filename)
     : base(connection, filename, new StartOutgoingRead())
 {
 }
コード例 #11
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));
        }
コード例 #12
0
ファイル: RemoteWriteTransfer.cs プロジェクト: sotaria/gsf
 public RemoteWriteTransfer(ITransferChannel connection, string filename)
     : base(connection, filename, new StartOutgoingWrite())
 {
 }
コード例 #13
0
ファイル: TftpClient.cs プロジェクト: vorot/tftp.net
        /// <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));
        }
コード例 #14
0
ファイル: TftpClient.cs プロジェクト: vorot/tftp.net
        /// <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));
        }