[英]WinSCP: see progress while upload/download file
I use the WinSCP .NET Library to upload/download files from a SFTP server by using PutFiles(..)
and GetFiles(..)
. 我使用WinSCP .NET库通过使用
PutFiles(..)
和GetFiles(..)
从SFTP服务器上载/下载文件。
Is there a way to see the progress while uploading/downloading files of this server? 上传/下载该服务器文件时,是否有办法查看进度? So for example, to get the percentage of the file-size, which is already downloaded.
因此,例如,要获取已下载的文件大小的百分比。
Thanks, Michael 谢谢迈克尔
There's a FileTransferProgress
event on the Session
class of the WinSCP library . WinSCP库的
Session
类上有一个FileTransferProgress
事件。
You just have to register for that event and then update your UI from within that handler: 您只需要注册该事件,然后从该处理程序中更新您的UI:
using (Session session = new Session())
{
// Will continuously report progress of transfer
session.FileTransferProgress += SessionFileTransferProgress;
/* Down / upload code here */
}
void SessionFileTransferProgress(object sender, FileTransferProgressEventArgs e)
{
// Print transfer progress
Console.Write("\r{0} ({1:P0})", e.FileName, e.FileProgress);
}
Please note that FileTransferProgressEventArgs.Side
enables you to tell if the event args are for an upload or a download. 请注意,使用
FileTransferProgressEventArgs.Side
事件args是用于上传还是下载。 Other properties contain information about speed of transfer, the file currently transferred etc... 其他属性包含有关传输速度,当前传输的文件等信息。
Here's the complete doc for it: http://winscp.net/eng/docs/library_session_filetransferprogress 这是完整的文档: http : //winscp.net/eng/docs/library_session_filetransferprogress
Edit: the event is called at the beginning of each new transfer (file) and then at most once a second for each transfer. 编辑:在每次新传输(文件)开始时调用该事件,然后每次传输最多每秒一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.