[Tutor] paramiko again
David
david at abbottdavid.com
Sun May 10 00:27:28 CEST 2009
Matt Herzog wrote:
> 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 ---------------------------
>
>
Your going to have to read up on it. Download the source here;
http://github.com/robey/paramiko/downloads
Then look at the demos folder where you will see an example for sftp like;
# now, connect and use paramiko Transport to negotiate SSH2 across the
connection
try:
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password, hostkey=hostkey)
sftp = paramiko.SFTPClient.from_transport(t)
More information about the Tutor
mailing list