问题描述
我正在尝试使用我编写的简单C ++程序连接到学校的ssh服务器。我的Windows计算机已安装了OpenSSH Client,并且能够使用命令提示符建立连接。
这是通过命令提示符运行的方式:
C:\Users\Username>ssh [email protected]
Password:
Last login: Sat Sep 5 15:20:44 2020 from 117.194.240.211
username@example:~$
我希望使用我编写的简单C ++程序来复制此操作。这是代码。
#include <iostream>
#include <cstring>
#include <stdlib.h>
using namespace std;
int main()
{
string hostIP;
string username;
string password;
cout << "Welcome to SSH Program" << endl;
cout << "----------------------" << endl;
cout << "\nEnter host ip or name: ";
cin >> hostIP;
cout << "Enter username: ";
cin >> username;
cout << "\nConnecting...\n" << endl;
string composite = "ssh " + username + "@" + hostIP;
char command[100];
strcpy_s(command,composite.c_str());
system(command);
system("pause");
}
不幸的是,当我尝试运行该程序时,得到以下输出:
Welcome to SSH Program
----------------------
Enter host ip or name: example.server.name
Enter username: username
Connecting...
'ssh' is not recognized as an internal or external command,operable program or batch file.
Press any key to continue . . .
据我了解,仅当系统上未安装OpenSSH Client时,才会出现此消息。但这在命令提示符示例中得到了证明。
为什么会这样,有没有办法解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)