本文整理汇总了C#中Renci.SshNet.SftpClient.EndUploadFile方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.EndUploadFile方法的具体用法?C# SftpClient.EndUploadFile怎么用?C# SftpClient.EndUploadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Renci.SshNet.SftpClient
的用法示例。
在下文中一共展示了SftpClient.EndUploadFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadFilesFromFilemanager
private void UploadFilesFromFilemanager()
{
string destpathroot = txtRemoteFolderPath.Text;
if (!destpathroot.EndsWith("/"))
{
destpathroot += "/";
}
var filelist = new Dictionary<string, string>();
foreach (var item in lvLocalBrowser.SelectedItems.Cast<EXImageListViewItem>().Where(item => (string) item.Tag != "[..]"))
{
if ((string)item.Tag == "File")
{
filelist.Add(item.MyValue, destpathroot + Path.GetFileName(item.MyValue));
}
if ((string)item.Tag == "Folder")
{
string folder = Path.GetDirectoryName(item.MyValue);
folder = folder.EndsWith("\\") ? folder : folder + "\\";
string[] files = Directory.GetFiles(item.MyValue,
"*.*",
SearchOption.AllDirectories);
// Display all the files.
foreach (string file in files)
{
filelist.Add(Path.GetFullPath(file), destpathroot + Path.GetFullPath(file).Replace(folder,"").Replace("\\","/"));
}
}
}
long fulllength = filelist.Sum(file => new FileInfo(file.Key).Length);
MessageBox.Show(Tools.Misc.LengthToHumanReadable(fulllength));
var ssh = new SftpClient(txtHost.Text, int.Parse(this.txtPort.Text), txtUser.Text, txtPassword.Text);
ssh.Connect();
ThreadPool.QueueUserWorkItem(state =>
{
long totaluploaded = 0;
foreach (var file in filelist)
{
CreatSSHDir(ssh, file.Value);
var s = new FileStream(file.Key, FileMode.Open);
var i = ssh.BeginUploadFile(s, file.Value) as SftpUploadAsyncResult;
while (!i.IsCompleted)
{
SetProgressStatus(totaluploaded + (long)i.UploadedBytes, fulllength);
}
ssh.EndUploadFile(i);
totaluploaded += s.Length;
}
MessageBox.Show(Language.SSHTransfer_StartTransfer_Upload_completed_);
EnableButtons();
ssh.Disconnect();
});
}