I am running a python script - ssh.py on my local machine to transfer file and directory from one remote server (ip = 35.189.168.20) to another remote server (ip = 10.243.96.94)
This is how my code looks:
HOST = "35.189.168.207"
USER = "sovith"
PASS = "xxx"
destHost = "10.243.96.94"
destUser = "root"
destPass = "xxx"
#SSH Connection
client1=paramiko.SSHClient()
client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client1.connect(HOST,username=USER,password=PASS)
#SFTP inside SSH server connection
with pysftp.Connection(host=destHost, username=destUser, password=destPass) as sftp:
#put build directory - sftp.put_r(source, destination)
sftp.put_r('/home/sovith/build' , '/var/tmp')
sftp.close()
client1.close()
Let me just tell you that all directory paths and everything is correct. I just feel that there's some logically mistake inside the code. The output i got after execution is :
Traceback (most recent call last):
File "ssh.py", line 108, in <module>
func()
File "ssh.py", line 99, in func
sftp.put_r('/home/sovith/nfmbuild' , '/var/tmp')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pysftp/__init__.py", line 427, in put_r
os.chdir(localpath)
FileNotFoundError: [Errno 2] No such file or directory: '/home/sovith/build'
Can you just correct the mistake from my code or suggest any better method to accomplish the task. In simpler words, i want a script to copy files and directory between two remote server.