ParallelSSH / ssh2-python

Python bindings for libssh2 C library.
https://parallel-ssh.org
GNU Lesser General Public License v2.1
228 stars 70 forks source link

Lib in stuck if the access to a remote directory is not possible (not existing dir) #152

Closed deneb78it closed 2 years ago

deneb78it commented 2 years ago

The scope of my code is to reach a remote server and remove logs from a directory. Before removing logs, I list the files with ls -l.

The same command works fine if the directory exists. It goes in stuck if the folder does not exits.

relevant code:

def remove_logs(self):
            try:
                self.channel.shell()                
                self.channel.write('ls -l /var/log/bbb/ \n')
                size, data = self.channel.read()
                output = output + 'logdir 2 before delete\n' + data.decode() + '\n'
                self.channel.write('rm /var/log/bbb/FW* \n')
                time.sleep(1)
                self.channel.write('ls -l /var/log/bbb/ \n')
                size, data = self.channel.read()
                output = output + 'logdir 2 after delete\n' + data.decode() + '\n'
            except:
                return "command error"
            return "command sent" + '\n' + output

For this server the folder /var/log/bbb/ does not exist. When I execute the code, it goes in stuck as it reaches the read instruction below.

                self.channel.write('ls -l /var/log/bbb/ \n')
                size, data = self.channel.read()

If I execute the command manually, this is the output:

    ls -l /var/log/bbb/
    ls: cannot access '/var/log/bbb/': No such file or directory

How can I fix? Thanks

pkittenis commented 2 years ago

Thanks for the interest.

Use parallel-ssh for high level clients based on this library.

The issue tracker is for issues with the code, not instructions on how to use.