0

I need to copy a number of files from one PC to another using scp. Of course I can manually do it one by one, but since they are several files and each one can take up to one hour, I would like to automate this with a simple script. Normally I would simply do this:

import subprocess

FILES_NAMES = [
    'file_1.raw',
    'file_2.raw',
]

for fname in FILES_NAMES:
    subprocess.run(['scp', f'user@pc:/path/to/files/{fname}', '.'])

but it keeps asking for the password each iteration.

Is it possible to do something like

for fname in FILES_NAMES:
    subprocess.run(['scp', f'user@pc:/path/to/files/{fname}', '.'], propmt_password='hardcode_your_super_secure_password_here')
user171780
  • 2,243
  • 1
  • 20
  • 43
  • Does this answer your question? [Sending a password over SSH or SCP with subprocess.Popen](https://stackoverflow.com/questions/15166973/sending-a-password-over-ssh-or-scp-with-subprocess-popen) – Peter234 Jul 03 '23 at 11:59

1 Answers1

0

Maybe you can use this type of code like using sshpass and then give your password then file paths

import subprocess

FILES_NAMES = [
    'file_1.raw',
    'file_2.raw',
]

for fname in FILES_NAMES:
    subprocess.run(['sshpass', '-p', 'YOUR_PASSWORD', 'scp', f'user@pc:/path/to/files/{fname}', '.'])