Beispiel #1
0
        private string Store(string pathname)
        {
            var filePath      = System.IO.Path.Combine(this._currentUser.HomeDir, pathname.Replace("~", "/"));
            var directoryPath = (new FileInfo(filePath)).Directory.FullName;

            if (!System.IO.Directory.Exists(directoryPath))
            {
                System.IO.Directory.CreateDirectory(directoryPath);
            }

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

                SetupDataConnectionOperation(state);

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

            return("450 Requested file action not taken");
        }
Beispiel #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();
            }
        }