Sunday, July 5, 2009

Paramiko hangs.

I was looking at paramiko for use in scripts and an application I was writing where I needed to do some secure ftp. Seems like I should've recognized this, but I was caught by surprise how it would handle closing the connection when python closed. I assumed the connection would close just like an open file (so that upon exiting the python shell, it would close). However, I found that the shell hung. At first I thought it was a bug in the library, but really it's just that paramiko needs you to explicitly close the connection.

def upload_file(host, user, key, remote_filename, data):
t = paramiko.Transport(host)
t.auth_publickey(user, key)

sftp = paramiko.SFTPClient.from_transport(t)

with tempfile.NamedTemporaryFile() as f:
sftp.put(, remote_filename)

Another one of those situations where the answer should be obvious...

No comments:

Post a Comment