2016-09-22 19 views
1

現在、WinSCPを使用して1kbファイルをサーバーに転送するために、C#でクライアントコードを書き込もうとしています。次のコードは動作しますが、完全な手順には約11秒かかります。コードは、接続のネゴシエーションとユーザーの認証に10秒かかります。実際のファイル転送は非常に高速です。WinSCP SCP接続時間の改善

Process winscp = new Process(); 
winscp.StartInfo.FileName = "winscp.com"; 
winscp.StartInfo.Arguments = "/xmllog=\"" + "sftp.txt" + "\""; 
winscp.StartInfo.UseShellExecute = false; 
winscp.StartInfo.RedirectStandardInput = true; 
winscp.StartInfo.RedirectStandardOutput = true; 
winscp.StartInfo.CreateNoWindow = true; 
winscp.Start(); 

// Feed in the scripting commands 
winscp.StandardInput.WriteLine("option batch abort"); 
winscp.StandardInput.WriteLine("option confirm off"); 

List<string> FtpCommands = new List<string> 
{ 
    string.Format("open scp://{0}:{1}@{2}:22",CONNECTION_SFTP_USER,CONNECTION_SFTP_PASSWORD, CONNECTION_SFTP_IP), 
    string.Format("put \"{0}\" /home/pi/progs/programs/{1}", file, program), 
    "exit" 
}; 

LogMessage("Sending ftp commands"); 
foreach (var ftpCommand in FtpCommands) 
{ 
    LogMessage(ftpCommand); 
    winscp.StandardInput.WriteLine(ftpCommand); 
} 

winscp.StandardInput.Close(); 

// Collect all output (not used in this example) 
string output = winscp.StandardOutput.ReadToEnd(); 

// Wait until WinSCP finishes 
winscp.WaitForExit(); 

私のコードは、サーバーを編集せずWinSCPのウェブサイト
https://winscp.net/eng/docs/guide_dotnet#csharp_example

から「フルC#の例」の編集したバージョンであり、私は転送時間を短縮するために作ることができるすべての変更はありますか?

答えて

1

SFTPプロトコル(sftp://)を使用してください。 WinSCPのSCPプロトコルは、WinSCPが自動化に適した環境を確認して調整する必要があるため、長い接続時間を必要とします。とにかくSCPプロトコルは時代遅れです。

実際に何らかの理由でSCPを使用する必要がある場合は、環境調整を無効にすることができます。

いずれにしても、winscp.exeは自分でバイナリドライブしないでください。代わりにWinSCP .NET assemblyを使用してください。それはあなたに多くの面倒を節約します。 the linkでもあなた自身がそれを示唆しています。

関連する問題