On Sun, Oct 11, 2009 at 6:03 AM, Eric Noulard <[email protected]> wrote: > 2009/10/11 Milan Andric <[email protected]>: >> Hello, >> >> Is it possible to use paramiko to transfer a file between two remote >> servers? Scp supports this but I could not get it to work with >> non-standard ssh ports (not 22). Like: >> >> scp [email protected]:/over/here/xyz.tgz >> [email protected]:/some/dir/ >> >> This doesn't respect the -P flag for the port. >> >> So I'm trying to figure out if paramiko can help me transfer a file >> between two remote servers without doing the transfer locally first. > > Using paramiko you should be able to do it "in-memory" for example > using 2 SFTPFiles: > http://www.lag.net/paramiko/docs/paramiko.SFTPFile-class.html > > Something like: > remote1 = SSHClient() > remote1.load_system_host_keys() > remote1.connect('remote1.com') > sftp1 = remote1.open_sftp() > remote2 = SSHClient() > remote2.load_system_host_keys() > remote2.connect('remote1.com') > sftp2 = remote2.open_sftp() > > file1 = sftp1.open("/over/here/xyz.tgz",'r') > file2 = sftp2.open("/some/dir/xyz.tgz",'w') > > then do appropriate loop for reading from file1 > and writing to file2. > remote1.connect('remote1.com') may be replaced > with an extra port=<portval> argument. >
This sounds awesome! I think this is the way to go. > Concerning ssh/scp, may be you ssh to one remote host > and launch scp from there? Something like: > > ssh [email protected]:/some/dir scp > [email protected]:/over/here/xyz.tgz . The problem with this is that I need to also copy and remove the private key around from whatever host I want to ssh from. I would like to avoid that extra management step if possible since it might involve leaving a stray private key around. So it would look more like : scp ../private/id_rsa_remote2 -i ../private/id_rsa_remote1 [email protected]:/home/user/tmp-id_rsa_remote2 ssh -i ../private/id_rsa_remote1 [email protected] "scp /my/build/file.tgz -i /home/user/tmp-id_rsa_remote2 [email protected]:/my/deploy/dir && rm /home/user/tmp-id_rsa_remote2" Thanks again, Milan _______________________________________________ paramiko mailing list [email protected] http://www.lag.net/cgi-bin/mailman/listinfo/paramiko
