public override async Task Download(string path, string localPath) { using (var f = new FileStream(localPath, FileMode.Create, FileAccess.ReadWrite)) { await _sftpc.DownloadAsync(path, f); } }
/// <summary> /// Downloads the file asynchronous. /// </summary> /// <param name="path">The path.</param> /// <param name="ctk">The CTK.</param> /// <returns></returns> public override async Task <byte[]> DownloadFileAsync(string path, CancellationToken ctk = default(CancellationToken)) { await _ensureConnected(ctk); using (var ms = new MemoryStream(80 * 1024)) { await _client.DownloadAsync(path, ms, u => { }); return(ms.ToArray()); } }
/// <summary> /// Downloads the file asynchronous. /// </summary> /// <param name="path">The path.</param> /// <param name="ctk">The CTK.</param> /// <returns></returns> public async Task <byte[]> DownloadFileAsync(string path, CancellationToken ctk = default(CancellationToken)) { using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5))) using (var linked = CancellationTokenSource.CreateLinkedTokenSource(ctk, cts.Token)) { using (var sFtpClient = new Renci.SshNet.SftpClient(new ConnectionInfo(Host, Port, Credentials.UserName, new PasswordAuthenticationMethod(Credentials.UserName, Credentials.Password)))) { sFtpClient.Connect(); using (var ms = new MemoryStream()) { await sFtpClient.DownloadAsync(path, ms, u => { }); return(ms.ToArray()); } } } }