Created
May 5, 2011 13:50
-
-
Save jaymzcd/957066 to your computer and use it in GitHub Desktop.
zipAndTrans.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2 | |
| import os | |
| import sys | |
| import paramiko | |
| import zipfile | |
| local_file = sys.argv[1] | |
| KNOWN_HOSTS = os.path.join(os.getenv("HOME"), '.ssh', 'known_hosts') | |
| CONFIG = dict(host='example.com', username='root', password='passwd') | |
| TARGET_PATH = '/tmp/' | |
| path, filename = os.path.split(local_file) | |
| filename, ext = os.path.splitext(filename) | |
| local_zip = os.path.join(path, filename+'.zip') | |
| zip_file = zipfile.ZipFile(local_zip, 'w') | |
| zip_file.write(local_file) | |
| zip_file.close() | |
| ssh = paramiko.SSHClient() | |
| ssh.load_host_keys(KNOWN_HOSTS) | |
| ssh.connect(CONFIG['host'], username=CONFIG['username'], password=CONFIG['password']) | |
| sftp = ssh.open_sftp() | |
| sftp.put(local_file, TARGET_PATH+filename+ext) | |
| sftp.put(local_zip, TARGET_PATH+filename+'.zip') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment