I'm using Renci SSH.NET as SFTP client in C#.
Now I'm making a progress bar with this API. I tried with async and await, but I could not find the solution for getting downloaded bytes. I tried this way:
Could you let me know problem with my code?
Is there any way to try using async, await with Renci SSH.NET? And get some downloaded or uploaded bytes from API.
IAsyncResult UploadResult = sftp.BeginUploadFile(stream, remotepath + "/" +
Path.GetFileName(localpath));
SftpUploadAsyncResult UploadProgress = new SftpUploadAsyncResult(null, UploadResult.AsyncState);
Window_Progress wp = new Window_Progress();
Point _pt = MainWindow.current.PointToScreen(new
Point((MainWindow.current.Width - wp.Width) / 2,
(MainWindow.current.Height - wp.Height) / 2));
wp.Left = _pt.X;
wp.Top = _pt.Y;
while (!UploadProgress.IsCompleted)
{
UploadProgress = new SftpUploadAsyncResult(null,UploadResult.AsyncState);
Thread.Sleep(10);
wp.PartialProgressBar.Value = (UploadProgress.UploadedBytes /
FilesAndDirectory.GetSize(localpath) * 100);
}
UploadProgress.AsyncWaitHandle.WaitOne();
wp.Close();