当前位置: 首页>>代码示例>>C#>>正文


C# SftpClient.EndDownloadFile方法代码示例

本文整理汇总了C#中Renci.SshNet.SftpClient.EndDownloadFile方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.EndDownloadFile方法的具体用法?C# SftpClient.EndDownloadFile怎么用?C# SftpClient.EndDownloadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Renci.SshNet.SftpClient的用法示例。


在下文中一共展示了SftpClient.EndDownloadFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DownloadFilesFromServer

                private void DownloadFilesFromServer()
                {
                    try
                    {
                        var filelist = new Dictionary<SftpFile, string>();
                        var remfold = txtRemoteFolderPath.Text.EndsWith("/") ? txtRemoteFolderPath.Text : txtRemoteFolderPath.Text += "/";
                        var ssh = new SftpClient(txtHost.Text, int.Parse(txtPort.Text), txtUser.Text, txtPassword.Text);
                        ssh.Connect();
                        foreach (var i in lvSSHFileBrowser.SelectedItems.Cast<EXImageListViewItem>().Select(item => item.Tag as SftpFile))
                        {
                            if (i.IsRegularFile)
                            {
                                filelist.Add(i, Path.Combine(txtLocalBrowserPath.Text, i.Name));
                            }
                            if (i.IsDirectory)
                            {
                                foreach (var file in GetFilesRecur(ssh, i))
                                {
                                    var i1 = file.FullName.Replace(remfold, "");
                                    var i2 = i1.Replace('/', '\\');
                                    var i3 = Path.Combine(txtLocalBrowserPath.Text, i2);
                                    filelist.Add(file, i3);
                                }
                            }
                        }
                        long totalsize = filelist.Sum(pair => pair.Key.Length);
                        var result = MessageBox.Show(string.Format(Language.SSHTransfer_DownloadFilesFromServer_Download__0__in__1__files_ + "\r\n" + Language.SSHTransfer_DownloadFilesFromServer_Destination_directory__2_, Tools.Misc.LengthToHumanReadable(totalsize), filelist.Count, txtLocalBrowserPath.Text), "Downloading", MessageBoxButtons.YesNoCancel);
                        if (result!=DialogResult.Yes)
                        {
                            EnableButtons();
                            return;
                        }
                        long totaluploaded = 0;
                        ThreadPool.QueueUserWorkItem(state =>
                            {
                                foreach (var file in filelist)
                                {
                                    if (!Directory.Exists(Path.GetDirectoryName(file.Value)))
                                    {
                                        Tools.Misc.ebfFolderCreate(Path.GetDirectoryName(file.Value));
                                    }
                                    var asynch = ssh.BeginDownloadFile(file.Key.FullName,
                                                                       new FileStream(file.Value, FileMode.Create));
                                    var sftpAsynch = asynch as SftpDownloadAsyncResult;

                                    while (!sftpAsynch.IsCompleted)
                                    {
                                        SetProgressStatus(totaluploaded + (long)sftpAsynch.DownloadedBytes, totalsize);
                                    }
                                    totaluploaded += file.Key.Length;
                                    ssh.EndDownloadFile(asynch);
                                }
                                EnableButtons();
                                ssh.Disconnect();
                                MessageBox.Show(Language.SSHTransfer_DownloadFilesFromServer_Download_finished);
                            });
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
开发者ID:hmaster20,项目名称:mRemoteNC,代码行数:62,代码来源:UI.Window.SSHTransfer.cs

示例2: DownloadFileAsync

        private Task DownloadFileAsync(SftpClient client, string remoteFullName, string localFullName)
        {
            var fileStr = new FileStream(localFullName, FileMode.Create);

            return Task.Factory.FromAsync(
                (callback, obj) => 
                    client.BeginDownloadFile(remoteFullName, fileStr, callback, obj, filePosition => 
                        progress.Report(filePosition.ToString(CultureInfo.InvariantCulture))),
                result =>
                {
                    client.EndDownloadFile(result);
                    if (result.IsCompleted)
                    {
                        fileStr.Close();
                    }
                    progress.ReportLine(string.Format("File downloaded: {0}", remoteFullName));
                },
                null);
        }
开发者ID:dev4s,项目名称:2015-file-synchronizer,代码行数:19,代码来源:Synchronizer.cs


注:本文中的Renci.SshNet.SftpClient.EndDownloadFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。