paramikoを使ってsftp

pythonでsftpでファイルを転送したり取得したりするのに、paramikoを使えるということで、いろいろ試してみました。
いろいろといっても、リモートサーバのファイル一覧をprintしたり、ファイルを転送したり、取得したりしてみただけです。

# coding=utf-8
import paramiko

hostname = '***********'
port = 22
username = '*****'
password = '*****'


client = None
sftp_connection = None
try:
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    client.connect(hostname, port=port, username=username, password=password)
    sftp_connection = client.open_sftp()

    # ホームディレクトリのファイル一覧をprint
    files = sftp_connection.listdir()
    for remote_file in files:
        print remote_file

    # ファイルを取得
    sftp_connection.get('/path/to/remotefile', '/path/to/local')

    # ファイルを転送
    sftp_connection.put('/path/to/localfile', '/path/to/remote')

except:
    raise
finally:
    if client:
        client.close()
    if sftp_connection:
        sftp_connection.close()