/// <summary> /// Request a Download action on the targeted file. /// </summary> /// <param name="filename">The local file that will be written to</param> /// <param name="cancelToken">The token to cancel the query</param> /// <param name="progress">The progress monitor</param> /// <param name="options">The query-specific options</param> /// <returns>A Task</returns> public async Task Download(string filename, CancellationToken cancelToken, ProgressMonitorBase progress = null, FtpOptions options = null) { using (var filestream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None)) await Download(filestream, cancelToken, progress, options); }
/// <summary> /// Request a Download action on the targeted file. /// </summary> /// <param name="stream">The stream that will be written to</param> /// <param name="progress">The progress monitor</param> /// <param name="options">The query-specific options</param> /// <returns>A Task</returns> public async Task Download(Stream stream, ProgressMonitorBase progress = null, FtpOptions options = null) { await Download(stream, CancellationToken.None, progress, options); }
/// <summary> /// Request a Download action on the targeted file, returning a string. /// </summary> /// <param name="encode">The encoding to use to reclaim the data into a string</param> /// <param name="progress">The progress monitor</param> /// <param name="options">The query-specific options</param> /// <returns>The full string of the targeted file</returns> public async Task <string> DownloadString(Encoding encode, ProgressMonitorBase progress = null, FtpOptions options = null) { return(await DownloadString(encode, CancellationToken.None, progress, options)); }
/// <summary> /// Request a Download action on the targeted file, returning a string. /// </summary> /// <param name="encode">The encoding to use to reclaim the data into a string</param> /// <param name="cancelToken">The token to cancel the query</param> /// <param name="progress">The progress monitor</param> /// <param name="options">The query-specific options</param> /// <returns>The full string of the targeted file</returns> public async Task <string> DownloadString(Encoding encode, CancellationToken cancelToken, ProgressMonitorBase progress = null, FtpOptions options = null) { using (var mem = new MemoryStream()) { await Download(mem, cancelToken, progress, options); using (var reader = new StreamReader(mem, encode)) return(await reader.ReadToEndAsync()); } }
/// <summary> /// Request a Download action on the targeted file, returning an array of bytes. /// </summary> /// <param name="progress">The progress monitor</param> /// <param name="options">The query-specific options</param> /// <returns>The full array of bytes of the targeted file</returns> public async Task <byte[]> DownloadData(ProgressMonitorBase progress = null, FtpOptions options = null) { return(await DownloadData(CancellationToken.None, progress, options)); }
/// <summary> /// Request a Download action on the targeted file, returning an array of bytes. /// </summary> /// <param name="cancelToken">The token to cancel the query</param> /// <param name="progress">The progress monitor</param> /// <param name="options">The query-specific options</param> /// <returns>The full array of bytes of the targeted file</returns> public async Task <byte[]> DownloadData(CancellationToken cancelToken, ProgressMonitorBase progress = null, FtpOptions options = null) { using (var mem = new MemoryStream()) { await Download(mem, cancelToken, progress, options); return(mem.ToArray()); } }
/// <summary> /// Query the file size of the target. /// </summary> /// <param name="options">The query-specific options</param> /// <returns>The size of the targeted file</returns> public async Task <long> GetFileSize(FtpOptions options = null) { return(await GetFileSize(CancellationToken.None, options)); }
/// <summary> /// Query the last modified time of the target. /// </summary> /// <param name="options">The query-specific options</param> /// <returns>The last modified time of the targeted file</returns> public async Task <DateTime> GetDatestamp(FtpOptions options = null) { return(await GetDatestamp(CancellationToken.None, options)); }
/// <summary> /// Query the Current directory. /// </summary> /// <param name="options">The query-specific options</param> /// <returns>The working directory</returns> public async Task <string> PrintWorkingDirectory(FtpOptions options = null) { return(await PrintWorkingDirectory(CancellationToken.None, options)); }
/// <summary> /// Query the Current directory. /// </summary> /// <param name="cancelToken">The token to cancel the query</param> /// <param name="options">The query-specific options</param> /// <returns>The working directory</returns> public async Task <string> PrintWorkingDirectory(CancellationToken cancelToken, FtpOptions options = null) { cancelToken.ThrowIfCancellationRequested(); FtpWebRequest request = Handler.MakeRequest(cancelToken, options, Target, WebRequestMethods.Ftp.PrintWorkingDirectory); using (var response = (FtpWebResponse)await request.GetResponseAsync()) { cancelToken.ThrowIfCancellationRequested(); return(response.StatusDescription); } }
/// <summary> /// Request a RemoveDirectory action on the targeted Directory. The target must exists. /// </summary> /// <param name="options">The query-specific options</param> /// <returns>A Task</returns> public async Task RemoveDirectory(FtpOptions options = null) { await RemoveDirectory(CancellationToken.None, options); }
/// <summary> /// Request a Delete action on the targeted file. /// </summary> /// <param name="options">The query-specific options</param> /// <returns>A Task</returns> public async Task DeleteFile(FtpOptions options = null) { await DeleteFile(CancellationToken.None, options); }
/// <summary> /// Request a Rename action on the targeted file or directory. /// </summary> /// <param name="newName">The new name for the file or directory</param> /// <param name="options">The query-specific options</param> /// <returns>A Task</returns> public async Task Rename(string newName, FtpOptions options = null) { await Rename(newName, CancellationToken.None, options); }
/// <summary> /// Query the details of a list of files and directories in the targeted directory. /// </summary> /// <param name="cancelToken">The token to cancel the query</param> /// <param name="options">The query-specific options</param> /// <returns>A detailed list of all the files and directories</returns> public async Task <List <string> > ListDetails(CancellationToken cancelToken, FtpOptions options = null) { cancelToken.ThrowIfCancellationRequested(); FtpWebRequest request = Handler.MakeRequest(cancelToken, options, Target, WebRequestMethods.Ftp.ListDirectoryDetails); using (var response = (FtpWebResponse)await request.GetResponseAsync()) { cancelToken.ThrowIfCancellationRequested(); using (var reader = new StreamReader(response.GetResponseStream())) { var list = new List <string>(); while (reader.Peek() != -1) { list.Add(await reader.ReadLineAsync()); cancelToken.ThrowIfCancellationRequested(); } return(list); } } }
/// <summary> /// Query the details of a list of files and directories in the targeted directory. /// </summary> /// <param name="options">The query-specific options</param> /// <returns>A detailed list of all the files and directories</returns> public async Task <List <string> > ListDetails(FtpOptions options = null) { return(await ListDetails(CancellationToken.None, options)); }