[Tutor] paramiko again

Matt Herzog msh at blisses.org
Sat May 9 23:11:28 CEST 2009


Hello again.

This code comes straight from the http://oreilly.com/catalog/9780596515829/ book.

The only actual code I changed was s/get/put on the second to last line. The author says I ought to be able to do this and have it Just Work. There are several things I don't understand. Would be nice if the books' author was on this list so I could ask him directly. Heh.

The code runs but does not upload any files. I would rather be specifying the local dir on the source machine rather than path on the destination. 

1. How can paramiko know whether the dir_path is on the local vs remote system?
2. I can't find sftp.put or sftp.get in ipython. Are they part of paramiko? If not, where do they come from?

Thanks for any insight.

------------------- begin --------------------------
#!/usr/bin/env python 
import paramiko 
import os 
hostname = '192.168.1.15' 
port = 22 
username = 'revjimjones' 
password = 'C0ol4id3' 
dir_path = '/home/revjimjones/logs' 
if __name__ == "__main__": 
    t = paramiko.Transport((hostname, port)) 
    t.connect(username=username, password=password) 
    sftp = paramiko.SFTPClient.from_transport(t) 
    files = sftp.listdir(dir_path) 
    for f in files: 
        print 'Uploading', f 
        sftp.put(os.path.join(dir_path, f), f) 
    t.close() 

-------------------- end ---------------------------


-- 
I fear you speak upon the rack,
Where men enforced do speak anything.

- William Shakespeare


More information about the Tutor mailing list