首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >改进WinSCP SCP连接时间

改进WinSCP SCP连接时间
EN

Stack Overflow用户
提问于 2016-09-22 09:02:17
回答 1查看 517关注 0票数 1

我目前正在尝试用C#编写客户端代码,以便使用WinSCP将1kb文件传输到服务器。下面的代码可以工作,但整个过程大约需要11秒。代码需要10秒来协商连接和验证用户。实际的文件传输速度非常快。

代码语言:javascript
复制
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示例”的编辑版本。

示例

在不编辑服务器的情况下,是否可以进行任何更改以缩短传输时间?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-22 09:28:21

使用SFTP协议(sftp://)。WinSCP中的SCP协议有很长的连接时间,因为WinSCP需要检查和调整环境以实现自动化友好。而且SCP协议已经过时了。

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

无论如何,不要自己驱动winscp.exe二进制文件。使用WinSCP .NET组装代替。这给你省了不少麻烦。就连你指着自己的链接也表明了这一点。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39634633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档