2016-05-27 13 views
2

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)); 
       } 
      } 
     } 
    } 
} 
+4

これらをすべて1つに圧縮して転送し、サーバーで解凍するのはどうですか? – Evk

+0

@ Evk私はそのファイルを転送しようとしましたが、そのファイルを転送するのに3分しかかかりませんでしたが、 ローカルマシンのサーバ上にあるファイルを解凍する方法 – dhiraj

+1

sshアクセス権がある場合はhttps:// sshnet.codeplex.com/ library(または他のもの)。あなたがsshアクセスを持っていない、またはそれを使用したくない場合は、あなたのコードが改善されるかもしれません。確かではありません。しかし、まず簡単なオプションを確認してください。 – Evk

答えて

0

各ファイル(オープニング、クロージング、タイムスタンプを更新する)とかなりのオーバーヘッドがあります。したがって、多数の小さなファイルを転送するのはかなり非効率的です。

転送を並列化するためにできること

Session.ListDirectory(または再帰が必要な場合はSession.EnumerateRemoteFiles)を使用してファイルのリストを収集し、リストをバッチに分割し、それぞれを別のスレッドで転送します。

PowerShellスクリプトの例があります。コードをC#に再実装するのは難しいことではありません。

Automating download in parallel connections over SFTP/FTP protocol

関連する問題