0

I am new to Python 3, I have a question here.., Using Python libraries/modules like Paramiko

I was able to login into SFTP Server successfully. I want to copy / upload a file from Local server directory to specified SFTP server directory.

I was able to do it successfuly for one particular file, i.e., I was able to copy / upload a particular file from Local path to SFTP server path.

But , my question is how do I copy / upload all files in a particular Local directory to target SFTP server directory , in one go ?

Which Python library / module is good d for this task ?

Below is the code which I have developed :

So here in the below python code, I could upload only a single file from local path to the SFTP target path successfully , but how do I upload all files in a particular local path to the desired SFTP target path ? I need to do this in one go.

import paramiko
import os

SFTP_Server_Host = axdjuorjdf@ujt.com
SFTP_UserName = fbhipy
SFTP_Password = xxxxxxxxx

sftp_ssh = paramiko.SSHClient()
sftp_ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sftp_ssh.connect(hostname=SFTP_Server_Host ,username=SFTP_UserName ,password=SFTP_Password)

sftp_check = sftp_ssh.open_sftp()

print("Connected to SFTP server : " +SFTP_Server_Host)
print()
print("Username of SFTP server : " +SFTP_UserName)
print()

sftp_check.chdir('dev/sample/user/test_data')

sftp_check.mkdir('app_data')

sftp_check.put('C:\\Prod_data\\Sample_prod.csv','dev/sample/user/test_data/app_data/Sample_prod.csv')

print("File transfered to SFTP Server : " +SFTP_Server_Host)
print()

--> Here instead of mentioning a particular file name , how could I upload all files from 'C:\Prod_data\' to 'dev/sample/user/test_data/app_data/'? <--

Mech_Saran
  • 157
  • 1
  • 2
  • 9
  • @Martin Prikryl , could you help me on this ? – Mech_Saran May 27 '20 at 20:39
  • This has been answer many times already. For example: [Directory transfers with Paramiko](https://stackoverflow.com/q/4409502/850848) or [Recursive directory copy with Paramiko in Python](https://stackoverflow.com/q/21550106/850848). – Martin Prikryl May 28 '20 at 05:28
  • @MartinPrikryl, I have followed the respective links and tried doing it , but I have failed in getting the expected results. – Mech_Saran May 28 '20 at 13:42
  • *"I have failed"* is a useless problem description. We need [mcve]. – Martin Prikryl May 28 '20 at 14:04

0 Answers0