提高WinSCP连接SCP的时间

本文关键字:时间 SCP 连接 WinSCP 提高 | 更新日期: 2023-09-27 18:08:28

我目前正在尝试用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网站的"完整c#示例"的编辑版本
https://winscp.net/eng/docs/guide_dotnet csharp_example

在不编辑服务器的情况下,我可以做什么改变来减少传输时间吗?

提高WinSCP连接SCP的时间

使用SFTP协议(sftp://)。WinSCP中的SCP协议连接时间较长,需要对环境进行检查和调整,使其自动化。而且SCP协议已经过时了。

如果您出于某种原因(似乎不是这种情况)确实需要使用SCP,您可以尝试禁用环境调整。

在任何情况下,不要自己驱动winscp.exe二进制文件。请使用WinSCP . net程序集。它为你省去了很多麻烦。甚至连你指向自己的链接都表明。