1

I am trying to move the contents from source directory C:\report to the remote directory remote_server_path/Test. Below is the code that I am trying with. Instead of just moving the contents of C:\report, it moves along the folder as such to the remote location. Any recommendations on how this could not be done?

import paramiko
from scp import SCPClient
import os

# create variables
host = "host"
username = "uname"
password = "password"

# Move files from network drive to marketing server
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, username=username, password=password)
scp = SCPClient(ssh.get_transport())
scp.put('C:\\report', recursive=True, remote_path='remote_server_path/Test')
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
user3447653
  • 3,968
  • 12
  • 58
  • 100

1 Answers1

0

Use C:\report\* to select the files within the folder.

scp.put('C:\\report\\*', recursive=True, remote_path='remote_server_path/Test/')

Obligatory warning: Do not use AutoAddPolicy – You are losing a protection against MITM attacks by doing so. For a correct solution, see Paramiko "Unknown Server".

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992