public async Task <FtpResponse> PrintWorkingDirectoryAsync() { CheckLoggedIn(); var response = await ExecuteAsync("PWD"); response.CheckReturnCode(257); WorkingDirectory = response.Message.Split('"')[1]; Debug.WriteLine("Current directory is " + WorkingDirectory, "FtpClient"); LastResponse = response; return(response); }
public async Task <FtpResponse> DeleteFileAsync(string file) { if (string.IsNullOrEmpty(file)) { throw new ArgumentNullException("A directory name wasn't provided. Please provide one and try your request again."); } CheckLoggedIn(); var response = await ExecuteAsync("DELE " + file); response.CheckReturnCode(250); Debug.WriteLine("Deleted file " + file, "FtpClient"); LastResponse = response; return(response); }
private async Task <FtpResponse> ReadResponseAsync() { FtpResponse response = new FtpResponse(); var responseBuffer = new StringBuilder(); var reader = new DataReader(ftpSocket.InputStream); reader.InputStreamOptions = InputStreamOptions.Partial; while (true) { var loadedSize = await reader.LoadAsync(BUFFER_SIZE); if (loadedSize > 0) { responseBuffer.Append(reader.ReadString(loadedSize)); if (loadedSize < BUFFER_SIZE) { break; } } else { break; } } response.Raw = responseBuffer.ToString(); string[] msg = response.Raw.Split('\n'); var re = new Regex(@"^(?<rc>\d{3})\s{1}(?<message>.*)\r"); for (int i = 0; i < msg.Length - 1; i++) { var match = re.Match(msg[i]); if (match != null) { response.ReturnCode = int.Parse(match.Groups["rc"].Value); response.Message = match.Groups["message"].Value; break; } } if (Verbose) { for (int i = 0; i < msg.Length - 1; i++) { Debug.WriteLine(msg[i], "FtpClient"); } } LastResponse = response; return(response); }
public async Task <FtpResponse> ChangeWorkingDirectoryAsync(string directory) { if (string.IsNullOrEmpty(directory)) { throw new ArgumentNullException("A directory name wasn't provided. Please provide one and try your request again."); } CheckLoggedIn(); var response = await ExecuteAsync("CWD " + directory); response.CheckReturnCode(250); await PrintWorkingDirectoryAsync(); Debug.WriteLine("Current directory is " + WorkingDirectory, "FtpClient"); LastResponse = response; return(response); }
private async Task <FtpResponse> ExecuteAsync(String msg) { if (Verbose) { Debug.WriteLine(msg, "FtpClient"); } var writer = new DataWriter(ftpSocket.OutputStream); writer.WriteString(msg + "\r\n"); await writer.StoreAsync(); writer.DetachStream(); var response = await ReadResponseAsync(); LastResponse = response; return(response); }
public FtpException(FtpResponse response, Exception innerException) : base(response.Message, innerException) { }
public FtpException(FtpResponse response) : base(response.Message) { }
private async Task<FtpResponse> ReadResponseAsync() { FtpResponse response = new FtpResponse(); var responseBuffer = new StringBuilder(); var reader = new DataReader(ftpSocket.InputStream); reader.InputStreamOptions = InputStreamOptions.Partial; while (true) { var loadedSize = await reader.LoadAsync(BUFFER_SIZE); if (loadedSize > 0) { responseBuffer.Append(reader.ReadString(loadedSize)); if (loadedSize < BUFFER_SIZE) break; } else { break; } } response.Raw = responseBuffer.ToString(); string[] msg = response.Raw.Split('\n'); var re = new Regex(@"^(?<rc>\d{3})\s{1}(?<message>.*)\r"); for (int i = 0; i < msg.Length - 1; i++) { var match = re.Match(msg[i]); if (match != null) { response.ReturnCode = int.Parse(match.Groups["rc"].Value); response.Message = match.Groups["message"].Value; break; } } if (Verbose) { for (int i = 0; i < msg.Length - 1; i++) { Debug.WriteLine(msg[i], "FtpClient"); } } LastResponse = response; return response; }
private async Task<FtpResponse> ExecuteAsync(String msg) { if (Verbose) Debug.WriteLine(msg, "FtpClient"); var writer = new DataWriter(ftpSocket.OutputStream); writer.WriteString(msg + "\r\n"); await writer.StoreAsync(); writer.DetachStream(); var response = await ReadResponseAsync(); LastResponse = response; return response; }
public async Task<FtpResponse> PrintWorkingDirectoryAsync() { CheckLoggedIn(); var response = await ExecuteAsync("PWD"); response.CheckReturnCode(257); WorkingDirectory = response.Message.Split('"')[1]; Debug.WriteLine("Current directory is " + WorkingDirectory, "FtpClient"); LastResponse = response; return response; }
public async Task<FtpResponse> ChangeWorkingDirectoryAsync(string directory) { if (string.IsNullOrEmpty(directory)) { throw new ArgumentNullException("A directory name wasn't provided. Please provide one and try your request again."); } CheckLoggedIn(); var response = await ExecuteAsync("CWD " + directory); response.CheckReturnCode(250); await PrintWorkingDirectoryAsync(); Debug.WriteLine("Current directory is " + WorkingDirectory, "FtpClient"); LastResponse = response; return response; }
public async Task<FtpResponse> DeleteFileAsync(string file) { if (string.IsNullOrEmpty(file)) { throw new ArgumentNullException("A directory name wasn't provided. Please provide one and try your request again."); } CheckLoggedIn(); var response = await ExecuteAsync("DELE " + file); response.CheckReturnCode(250); Debug.WriteLine("Deleted file " + file, "FtpClient"); LastResponse = response; return response; }