top | item 3749266

Python Scripts for Downloading files via SFTP

34 points| phillytom | 14 years ago |engineering.monetate.com | reply

8 comments

order
[+] pak|14 years ago|reply
Um, instead of using Python and the pexpect module, just use /usr/bin/expect by itself. The Expect language is very simple [1] and could cut this script down to less than 10 lines, if all you need to do is automate a couple transfers.

The paramiko module is the "right" way of doing this in Python, and probably only appropriate if you need to integrate SFTP transactions into a larger, longer-running application.

Edit: I might add the use of a password in a command line argument is not advisable because it will get logged everywhere and show up in things like top, etc. Probably better to hardcode it or put it in a 0600 file.

[1]: http://en.wikipedia.org/wiki/Expect (In fact, there is a complete example for automating SFTP right in the article).

[+] sneak|14 years ago|reply
Just use key-based auth, for fuck's sake.

If you're going to keep credentials in plaintext on disk, at least make them keys and stop dicking about with expect.

[+] wiredfool|14 years ago|reply
From what I remember, paramiko is pretty straight forward when you're doing keys or password, but you need to hack in a little something if you're trying to connect to a server which insists on both.