我目前正在尝试用C#编写客户端代码,以便使用WinSCP将1kb文件传输到服务器。下面的代码可以工作,但整个过程大约需要11秒。代码需要10秒来协商连接和验证用户。实际的文件传输速度非常快。
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网站的“完整的WinSCP示例”的编辑版本。
在不编辑服务器的情况下,是否可以进行任何更改以缩短传输时间?
发布于 2016-09-22 09:28:21
使用SFTP协议(sftp://)。WinSCP中的SCP协议有很长的连接时间,因为WinSCP需要检查和调整环境以实现自动化友好。而且SCP协议已经过时了。
如果您确实出于某种原因需要使用SCP (似乎不是这样),您可以尝试禁用环境调整。
无论如何,不要自己驱动winscp.exe二进制文件。使用WinSCP .NET组装代替。这给你省了不少麻烦。就连你指着自己的链接也表明了这一点。
https://stackoverflow.com/questions/39634633
复制相似问题