C#WPFアプリケーションでSFTPを使用しているLinuxサーバー上で、サイズ85KBの4000個のzipファイルをアップロードしています。 このプロセス全体には30分かかります。SFTPを使用した多数のファイルの転送がC#で遅い
SFTPを使用してアップロードをスピードアップする方法はありますか?私も以前チルカットを使用していた
https://winscp.net/eng/docs/library
:
私はWinSCPの.NETアセンブリを使用しています。
は、ここに私のコードです:
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));
}
}
}
}
}
これらをすべて1つに圧縮して転送し、サーバーで解凍するのはどうですか? – Evk
@ Evk私はそのファイルを転送しようとしましたが、そのファイルを転送するのに3分しかかかりませんでしたが、 ローカルマシンのサーバ上にあるファイルを解凍する方法 – dhiraj
sshアクセス権がある場合はhttps:// sshnet.codeplex.com/ library(または他のもの)。あなたがsshアクセスを持っていない、またはそれを使用したくない場合は、あなたのコードが改善されるかもしれません。確かではありません。しかし、まず簡単なオプションを確認してください。 – Evk