Home > database >  How to add port argument in subprocess.Popen?
How to add port argument in subprocess.Popen?

Time:09-03

import subprocess
import os
p = subprocess.Popen(["scp", "test.txt", "[email protected]:/workspace/waic/data"])
sts = os.waitpid(p.pid, 0)

print('Done')

I got this message:

Host key verification failed.
lost connection

I want to copy files from a remote machine, but I don't know how to add a '-p 33' port argument. If I add it after 'scp -p 33', it gives another error:

No such file or directory: 'scp -p 33'

CodePudding user response:

Those are just additional parameters on the command line. Also fixing the flag "-P" (assuming you are using a standard unixlike scp):

p = subprocess.Popen(["scp", "-P", "33", "test.txt", "[email protected]:/workspace/waic/data"])

CodePudding user response:

You have 3 issues.

  1. You are not typing your arguments into the list of args correctly. Below is an example of how to properly do so.
  2. You have incorrect casing on your port argument.
  3. You are trying to scp but it is expecting a password, this should help.
import subprocess
import os
p = subprocess.Popen(["sshpass", "-p", "YOUR PASSWORD HERE",  "scp", "-P", "33", "test.txt", "[email protected]:/workspace/waic/data"])
sts = os.waitpid(p.pid, 0)

print('Done')
  • Related