1
我正在嘗試在C#中編寫客戶端代碼,以使用WinSCP將1kb文件傳輸到服務器。以下代碼有效,但完整的過程大約需要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();
我的代碼是「整個C#示例」的一個編輯的版本從WinSCP賦予網站
https://winscp.net/eng/docs/guide_dotnet#csharp_example
沒有編輯服務器,有沒有什麼變化,我可以做,以減少傳輸時間?