views:

117

answers:

1

How i can make sftp transport throught SSHClient on the remote server? I have local host and two remote. Remotes hosts are backup server and web server. I need find on backup server necessary backup file and put it on web server over sftp. Plz help me, i dont understand how i can make paramiko's sftp transport throught paramiko's SSHClient.

A: 

paramiko.SFTPClient

Example:

import paramiko
paramiko.util.log_to_file('/tmp/paramiko.log')

# Open a transport

host = "example.com"
port = 22
transport = paramiko.Transport((host, port))

# Auth

password = "foo"
username = "bar"
transport.connect(username = username, password = password)

# Go!

sftp = paramiko.SFTPClient.from_transport(transport)

# Download

filepath = '/etc/passwd'
localpath = '/home/remotepasswd'
sftp.get(filepath, localpath)

# Upload

filepath = '/home/foo.jpg'
localpath = '/home/pony.jpg'
sftp.put(filepath, localpath)

# Close

sftp.close()
transport.close()
leoluk
thats right, but this creat transport from my localhost to web or backup. I need sftp from backup to web and i starting script from my localhost. Bot must doing like this:"ssh [email protected]; scp backup.file [email protected]:/home/admin/tmp". How i understand scp isnt support by paramiko library, but it support sftp and i want make sftp tunnel from remote server to remote server? not from my localhost.
Denis