我正在编写一个C#代码,它将调用我的windows cmd并对其执行命令,但我被困在最后一个语句中,因为在执行“pscp”命令后,它要求输入“用户名密码”,我已经拥有但不知道我的代码如何处理它。
我的代码示例:
const string cmdtext = @"/k cd\&pscp.exe&pscp C:\Users\user\Desktop\Backup\standalone-full.xml username@hostname:/apps/tempdir/express/standalone-full.xml";
Process.Start(@"C:\Windows\system32\cmd.exe", cmdtext); // after executing this command, it asks for the username's password
Console.ReadLine();
答案 0 :(得分:0)
您可以尝试使用bitvise ssh客户端。您可以将密码放在该工具的命令行版本上。
不过,你应该使用powershell而不是C#来完成这些任务。答案 1 :(得分:-1)
我通常像这样打电话给pscp:
pscp -l <username> -pw <password> <options> <source> <host>:<target>
示例:
pscp -l root -pw root C:\myfile.txt 192.168.0.1:/home/myfile.txt
无效提示