1

I made a client server program using Paramiko. I manage to get a connection, and send command. For example if I send a 'ifconfig' command, it indeed returns the desired output. Yet, when I try to send an 'ls' command, it returns nothing. I need the server to let me use more complicated commands, like opening files, editing wordpress and so on.

This sends the 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())

When I send -

sshCommand('ifconfig')

Everything works. But, sending -

sshCommand('ls')

Could it be that for some reason I don't have permission to access the files? I also have the root password which is used to connect.

Any help would be appreciated.

salomon
  • 11
  • 2

1 Answers1

0

If you want to debug why the command does not work, read also the stderr.

See Command executed with Paramiko does not produce any output.


Though if you are going to manipulate files, do not use shell commands. Use SFTP.

See How to list all the folders and files in the directory after connecting through SFTP in Python.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992