I have a code where I have to login into a Unix server. After that I have to sftp into some server and have download few files to that Unix server. I am using Pythons' Paramiko command to login into Unix server. I know by using sftp.get(filepath, localpath), I can sftp files from SFTP server to local machine. However, my problem is I have to sftp those files into Unix server and not into local machine.
import paramiko
ip = ip
username = username
password = password
port = port
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,port,username,password)
remotefilepath = remotefilepath
unixserverlocalpath = unixserverlocalpath
transport = paramiko.Transport(host)
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
stdin,stdout,stderr=ssh.exec_command('some commands')
sftp.get(filepath, localpath)
stdin.write('Password')
stdin.flush()
outlines=stdout.readlines()
resp=''.join(outlines)
print(resp)
sftp.close()
transport.close()
This code is throwing error as it is trying to sftp files in my local machine rather than in unix server.