2

I need to copy many files created in a python script from local to a remote server. On the command prompt I use this line :

"pscp c:\users\myaccount\documents\foler\file.txt name@server:/home/folder".

But this requires a password that I can enter on the command prompt.

On my python script I "import os" then :

cmd = "pscp local_path server_path"

os.system(cmd)

But I don't know how to enter the password in my script.

Thanks

Community
  • 1
  • 1

1 Answers1

2

try using paramiko package https://docs.paramiko.org/en/2.4/

s = paramiko.SSHClient()
    s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    s.connect("xxx.xxx.xxx.xxx",22,username=xxx,password='',timeout=4)

    sftp = s.open_sftp()
    sftp.put('/home/me/file.ext', '/remote/home/file.ext')
Omer Anisfeld
  • 1,236
  • 12
  • 28