Reputation: 7196
I've a manual task where I ssh
onto a server, cd
to a folder and run a curl
command to download a file to that folder. I'm now trying to automate this in a Python program. I can use paramiko
to ssh to the server and run any commands:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(credentials)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('cd /path/to/folder/ && sudo curl -H \'X-JFrog-Art-Api:api_key\' -O "https://path/to/download/file.tar.xz"', timeout=600)
print(f'curl ssh_stdout: {ssh_stdout.readlines()}')
print(f'curl ssh_stderr: {ssh_stderr.readlines()}')
The file downloads correctly but the output that I expected in stdout
appears in stderr
. This is the stderr
:
curl ssh_stderr: [' % Total % Received % Xferd Average Speed Time Time Time Current\n', ' Dload Upload Total Spent Left Speed\n', '\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
...
0 0:04:36 0:04:35 0:00:01 57.6M\r 99 14.9G 99 14.9G 0 0 55.5M 0 0:04:36 0:04:36 --:--:-- 57.6M\r100 14.9G 100 14.9G 0 0 55.5M 0 0:04:36 0:04:36 --:--:-- 57.8M\n']
This hardly seems like a good way to automate my process. Is there a way to do this with some other library which may be better tailored for such an operation? I'm thinking of something like requests
.
Upvotes: 1
Views: 1101
Reputation: 202272
curl
outputs its progress to stderr.
Nothing wrong with your code, nor with Paramiko.
In shell, try:
curl https://www.example.com/ > stdout 2> stderr
Your will see that stdout
will contain example.com HTML contents and stderr
will contain curl
progress output.
Upvotes: 2