【发布时间】:2016-05-27 11:46:22
【问题描述】:
我正在使用 C# WPF 应用程序中的 SFTP 通过 Linux 服务器上传 4000 个大小为 85 KB 的 zip 文件。 整个过程需要 30 分钟。
有什么方法可以加快使用 SFTP 上传的速度吗?
我正在使用 WinSCP .NET 程序集:
https://winscp.net/eng/docs/library
我以前也用过 Chilkat。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WinSCP;
namespace SFTP_Demo
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
string line;
SessionOptions sessionoptions = new SessionOptions()
{
Protocol = WinSCP.Protocol.Sftp,
HostName = "172.168.1.7",
PortNumber = 22,
UserName = "lduser",
Password = "lduser",
GiveUpSecurityAndAcceptAnySshHostKey = true
};
using (Session session = new Session())
{
session.Open(sessionoptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
System.IO.StreamReader file = new System.IO.StreamReader(txtFile.Text);
while ((line = file.ReadLine()) != null)
{
transferResult = session.PutFiles(@"D:\Test\signature\ldoutput\"+line, "/SFTP/", false, transferOptions);
transferResult.Check();
counter++;
strbldr = strbldr.AppendLine(string.Format("{0} Upload of {1} succeeded", counter + 1.ToString(), line));
}
}
}
}
}
【问题讨论】:
标签: c# multithreading sftp winscp winscp-net