我做在SSH.NET/C#以下非常基本的任務可以從遠程服務器下載文件到本地路徑下載:如何確定文件完成SSH.NET
ConnectionInfo c = new PasswordConnectionInfo(remoteIP, port, username, password);
var sftp = new SftpClient(c);
sftp.Connect();
using (var stream = new FileStream(destinationFile, FileMode.Create))
{
//download the file to our local path
sftp.DownloadFile(fileName, stream);
stream.Close();
}
sftp.Disconnect();
我們確定文件是否完全下載成功,是否只是代碼塊到達stream.Close()?還是有更具體的方法來確定一切是否寫得好?
編輯:This post可能會有所幫助,如果你想看看有多少字節已被下載。它也使一個原始的進度條,這是方便的。我在帖子中測試了代碼,它確實有效。
謝謝!你太棒了! – starmandeluxe