private void GetList(IAsyncResult result) { if (!_userAuthenticated) { return; } if (_dataConnectionType == DataConnectionType.Active) { _dataClient.EndConnect(result); } else { _dataClient = _passiveListener.EndAcceptTcpClient(result); } var pathName = (string)result.AsyncState; var dataStream = new ClientStream(_dataClient.GetStream(), true); foreach (var directory in Directory.EnumerateDirectories(pathName)) { dataStream.SendDirectoryResult(new DirectoryInfo(directory)); } foreach (var file in Directory.EnumerateFiles(pathName)) { dataStream.SendFileResult(new FileInfo(file)); } _dataClient.Close(); _dataClient = null; _clientStream.SendFtpResult(FtpCode.ClosingDataConnection, "Transfer complete", true); }
private void SendFile(IAsyncResult result) { if (!_userAuthenticated) { return; } if (_dataConnectionType == DataConnectionType.Active) { _dataClient.EndConnect(result); } else { _dataClient = _passiveListener.EndAcceptTcpClient(result); } var fileName = (string)result.AsyncState; var dataStream = new ClientStream(_dataClient.GetStream()); using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { dataStream.SendFile(fileStream, _transferType); _dataClient.Close(); _dataClient = null; _clientStream.SendFtpResult(FtpCode.ClosingDataConnection, "File transfer complete", true); } }
public FtpSharpClientConnection(TcpClient client, FtpSharpSettings settings, Logger logger = null) { _tcpClient = client; _clientStream = new ClientStream(client.GetStream()); _settings = settings; _logger = logger; }