Search This Blog

Sunday, May 10, 2009

Best Dilbert Evar

Dilbert.com

paramiko to sftp without keys

Stupid server does not allow installation of ssh keys. This makes file transfers harder to automate from a cron job for example because scp and ssh have no --username --passwd options.

Python can help! I can sftp a whole dir of files to the sftp server with this script. My next task is to make paramiko accept filename extention wildcards. i.e. 'sftp *.csv mucknuck@sftp.computrid.com:'

import paramiko
import os

hostname = 'sftp.computrid.com'
port = 22
username = 'nucknuck'
password = '05N9289!'
dir_path = 'moo'
local_path = '/home/datasvcs/AIG/moo'

if __name__ == "__main__":
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
files = os.listdir(local_path)
for f in files:
print 'Uploading', f
sftp.put(os.path.join(dir_path, f), f)
t.close()