__author__ = 'Miraculous'

import sys
import paramiko
'''
a wrapper for remote scp
usage:
python rscp.py user host password remote_path current_file
'''
if __name__ == '__main__':
    try:
        args = sys.argv
        host, port, user, password = args[1], args[2], args[3], args[4]
        file_to_upload = args[5]
        remote_path = args[6]
        print 'scp: from'+file_to_upload+' to '+remote_path

        client = paramiko.SSHClient()
        client.load_system_host_keys()
        client.get_transport()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect(host, port, user, password)

        sftp = client.open_sftp()
        sftp.put(file_to_upload, remote_path)
        sftp.close()
        client.close()
        exit(0)
    except Exception, e:
        sys.stderr.write(e.message)
        sys.stderr.flush()
        exit(1)


