从 Windows 上的应用程序与 sftp (cygwin) 交互
在 Unix 上,您可以使用 Expect
和 Empty
等工具,使用伪终端与 sftp
等终端应用程序进行交互。我有一台安装了 cygwin 的 Windows 计算机,我的 C#
应用程序需要启动 sftp 会话以将一些文件传输到远程计算机。
我从这样的代码开始
var p = new Process();
p.StartInfo = new ProcessStartInfo
{
FileName = "sftp",
UseShellExecute = false,
CreateNoWindow = false,
RedirectStandardInput = true,
Arguments = username + "@" + server
};
p.Start();
p.StandardInput.WriteLine(password);
问题是 sftp 不会从 stdin 读取密码,只能从终端读取密码。这就是 Expect 的用武之地。除了在 cygwin 中安装 Expect
之外,还有什么方法可以从 C#
程序以交互方式向 sftp
发送密码?
On Unix you have tools like Expect
and Empty
for interacting with terminal applications like sftp
, using pseudo terminals. I have a Windows machine with cygwin installed on it and my C#
app needs to start an sftp session to transfer some files to a remote machine.
I started with some code like this
var p = new Process();
p.StartInfo = new ProcessStartInfo
{
FileName = "sftp",
UseShellExecute = false,
CreateNoWindow = false,
RedirectStandardInput = true,
Arguments = username + "@" + server
};
p.Start();
p.StandardInput.WriteLine(password);
The problem is that sftp
will not read a password from stdin
, only from the terminal. That's where Expect comes in. Outside of installing Expect
in cygwin is there any way to interactively send a password to sftp
from a C#
program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cygwin 有大量常见 UNIX 实用程序的软件包,包括expect 并且(可能)为空。理论上你仍然可以使用这些......(并不是说这将是最安全、紧凑或理想的选择......但它是一个选项!)
Cygwin has packages for tons of common UNIX utilities, including expect and (probably) empty. In theory you could still use those... (not that this would be the most secure, compact, or ideal option... but it's an option!)