Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from __future__ import with_statement
- import sys, os, hashlib, base64
- from getpass import getpass
- from contextlib import contextmanager
- import paramiko
- lampda = base64.decodestring
- @contextmanager
- def create_ssh(host):
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- try :
- print("attempt to create a connection using a private key...")
- ssh.connect("147.210.18.1", username="boubekki", look_for_keys=True)
- print("connected")
- yield ssh
- except :
- print("no private key available")
- username = raw_input("username: ")
- password = getpass()
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- print("a private key will be used for futur connexion...")
- try:
- print("creating connection")
- ssh.connect(host, username=username, password=password)
- print("connected")
- yield ssh
- except :
- print("fatal error")
- finally:
- print("closing connection")
- ssh.close()
- print("closed")
- def slpr(path, file_name):
- with create_ssh("147.210.18.1") as ssh:
- sftp = ssh.open_sftp()
- sftp.put(os.path.join(path, file_name),"/tmp/"+file_name)
- print("file uploaded to %s" % "/tmp/"+file_name)
- stdin, stdout, stderr = ssh.exec_command("imp -pz -2 -rv /tmp/"+file_name)
- print(stdout.read())
- print(stderr.read())
- if __name__ == "__main__":
- if (len(sys.argv)<1)
- raise Exception(lampda("SWwgbWFucXVlIHVuIGFyZ3VtZW50"))
- file_path = os.path.abspath(sys.argv[1])
- if not (os.path.isfile(file_path)):
- raise Exception("file does not exist")
- path, file_name = os.path.split(file_path)
- slpr(path, file_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement