我用Paramiko做了一个客户机-服务器程序。我设法获得连接,并发送命令。 例如,如果我发送一个“ifconfig”命令,它确实会返回所需的输出。然而,当我尝试发送“ls”命令时,它什么也不返回。我需要服务器让我使用更复杂的命令,比如打开文件、编辑wordpress等等
这将发送sshCommand:
def sshCommand(command, port=22):
sshClient = paramiko.SSHClient() # create SSHClient instance
sshClient.set_missing_host_key_policy(
paramiko.AutoAddPolicy()) # AutoAddPolicy automatically adding the hostname and new host key
sshClient.load_system_host_keys()
sshClient.connect(host, port, username, password)
stdin, stdout, stderr = sshClient.exec_command(command)
print(stdout.read())
当我发送-
sshCommand('ifconfig')
一切正常。 但是,发送-
sshCommand('ls')
可能是因为某种原因我没有访问这些文件的权限吗?我还有用于连接的根密码
任何帮助都将不胜感激
如果要调试命令不起作用的原因,请同时阅读
stderr
见Command executed with Paramiko does not produce any output
但是,如果要操作文件,请不要使用shell命令。使用SFTP
见How to list all the folders and files in the directory after connecting through SFTP in Python
相关问题 更多 >
编程相关推荐