public void DownloadToLocalFile(string filePath) { var connectionInfo = _connectionInfo.CreateConnectionInfo(); using (var client = new SftpClient(connectionInfo)) { client.Connect(); using (FileStream fs = File.OpenWrite(filePath)) client.OpenRead(Path.Combine(_path, Name)).CopyTo(fs); } }
private IEnumerable <SftpFilesValue> GetFiles(SftpConnectionInfo sftpConnectionInfo, string path) { var connectionInfo = sftpConnectionInfo.CreateConnectionInfo(); using (var client = new SftpClient(connectionInfo)) { client.Connect(); var files = client.ListDirectory(path); foreach (var file in files) { yield return(new SftpFilesValue(sftpConnectionInfo, path, file.Name)); } } }
private void WriteSftpFile(SftpConnectionInfo sftpConnectionInfo, string outputPath, Stream stream) { var connectionInfo = sftpConnectionInfo.CreateConnectionInfo(); using (var client = new SftpClient(connectionInfo)) { client.Connect(); byte[] fileContents; stream.Position = 0; using (MemoryStream ms = new MemoryStream()) { stream.CopyTo(ms); fileContents = ms.ToArray(); } client.WriteAllBytes(outputPath, fileContents); } }