Example #1
0
        private string List(string pathname)
        {
            pathname = NormalizeFilename(pathname);

            if (pathname != null)
            {
                var state = new DataConnectionListOperation {
                    Arguments = pathname
                };

                SetupDataConnectionOperation(state);

                return(string.Format("150 Opening {0} mode data transfer for LIST", _dataConnectionType));
            }

            return("450 Requested file action not taken");
        }
Example #2
0
        private void DoDataConnectionOperation(IAsyncResult result)
        {
            HandleAsyncResult(result);

            if (result.AsyncState is DataConnectionStoreOperation)
            {
                DataConnectionStoreOperation op = result.AsyncState as DataConnectionStoreOperation;

                try
                {
                    if (File.Exists(op.Arguments))
                    {
                        File.Delete(op.Arguments);
                    }
                }
                catch (Exception exc)
                {
                    Debug.WriteLine(exc.Message);
                }

                string response = string.Empty;

                using (NetworkStream dataStream = _dataClient.GetStream())
                {
                    long bytes = 0;


                    using (FileStream fs = new FileStream(op.Arguments, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 4096, FileOptions.SequentialScan))
                    {
                        bytes = CopyStream(dataStream, fs);
                    }

                    LoggingManager.WriteToLog("File connection", _clientIP + "(" + this._currentUser.Username + ")", "STOR");

                    response = "226 Closing data connection, file transfer successful";
                }

                this._dataClient.Close();
                this._dataClient = null;

                this._controlWriter.WriteLine(response);
                this._controlWriter.Flush();
            }
            else if (result.AsyncState is DataConnectionListOperation)
            {
                DataConnectionListOperation op = result.AsyncState as DataConnectionListOperation;

                string response;

                using (NetworkStream dataStream = _dataClient.GetStream())
                {
                    response = ListOperation(dataStream, op.Arguments);
                    //response = op.Operation(dataStream, op.Arguments);
                }

                _dataClient.Close();
                _dataClient = null;

                _controlWriter.WriteLine(response);
                _controlWriter.Flush();
            }
        }