def scp_get_files(self):
     """"""
     if self.conf != None:
         '''SET CONNECTION PREFS'''
         #self.set_connection_params()
         '''SET SSH CLIENT AND TRANSPORT'''
         self.create_Paramiko_SSHClient()
         scp = SCPClient(self.ssh_client.get_transport())
         self.logger.info("<== SCP CLASS STARTED GETTING files ==> ")
         scp.get(remote_path=self.ssh_scp_content_location,
                 local_path=self.ssh_target_dir)
         scp.close()
         self.logger.info("<== SCP CLASS HAS GOT ==> ")
         '''Check if it is actually here'''
         f_name = self.str_split_get_pop_elem(
             str_in=self.ssh_scp_content_location,
             delim_in='/',
             which_elem='LAST')
         copied_file = Path(self.ssh_target_dir + '\\' + f_name)
         if copied_file.is_file():
             self.logger.debug("<== File with name  ==> ")
             self.logger.debug("<==" + str(copied_file) + "==> ")
             self.logger.debug(
                 "<==  seems to be in place Now the question is it the right one  ---> "
             )
         else:
             raise ValueError(
                 "Configuration file is not PRESENT in the CLASS!!!")
     return
예제 #2
0
def grab_backup():
    # Make backup directory first
    os.makedirs(LOCAL_LOCATION)
    # Connect
    SSH_CLIENT = paramiko.SSHClient()
    SSH_CLIENT.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    SSH_CLIENT.connect(HOST,
                       port=SSH_PORT,
                       username=SSH_USER,
                       key_filename=SSH_KEY)
    scp = SCPClient(SSH_CLIENT.get_transport())
    scp.get(DB_DUMP_LOCATION, LOCAL_LOCATION)
    scp.close()
    SSH_CLIENT.close()
    cleanup()
예제 #3
0
def sshAttacker(host, user, passwd, comando):
	if comando == 'instalar':
		execute = 'tar xzf bittwist-linux-2.0.tar.gz && rm bittwist-linux-2.0.tar.gz && cd bittwist-linux-2.0/ && sudo make install'
	elif comando == 'desinstalar':
		execute = 'cd bittwist-linux-2.0/ && sudo make uninstall'
	elif comando == 'eliminar':
		execute = 'rm -rf bittwist-linux-2.0/ && sudo pkill bittwist'

	ssh = paramiko.SSHClient()
	ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
	ssh.connect(host, username=user, password=passwd)
	
	if comando == '':
		ssh.close()
		return

	if comando == 'instalar':
		scp = SCPClient(ssh.get_transport())	
		scp.put('./bittwist-linux-2.0.tar.gz', '~/')
		scp.close()

	transport = ssh.get_transport()
	session = transport.open_session()
	session.set_combine_stderr(True)
	session.get_pty()
	session.exec_command(execute)
	stdin = session.makefile('wb', -1)
	stdout = session.makefile('rb', -1)
	stdin.write(passwd + '\n')
	stdin.flush()

	if comando == 'instalar':
		for n in stdout.read().splitlines():
			print host +'----'+ n

	ssh.close()

	if comando == 'instalar':
		print 'Intalado Bittwist en '+host		
	elif comando == 'desinstalar':
		print 'Software desinstalado del host '+host
	elif comando == 'eliminar':
		print 'Directorio y proceso eliminados del host '+host
예제 #4
0
def deploy(ip):

    bkpDT = customdatetime("%d%b%Y_%H%M",0,0,0)
    app_path = "%s" %(str(sys.argv[1]))
    bkp_path = "/home/USER/Downloads/py/tarbkp/%s_Bkp.tar.gz" %(bkpDT)
    filename = path.basename(bkp_path)
    params = "-zcvf"
    SSH_PASSWORD = SSH_USERNAME = "******"
    Remote_tar_path = "/home/USER/test/bkptar"
#    script_path = os.getcwd()

    print "Filename : %r " % (filename)

    if subprocess.call(['tar',params ,bkp_path, app_path])!=True:
        print "\n\n#################### The backup is completed ####################"
    else:
        print "Some error occured while making tar, Terminating the Script"
        quit()

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_stdin = ssh_stdout = ssh_stderr = None
    ssh.connect(ip, port=22, username = SSH_USERNAME, password = SSH_PASSWORD)
    scp = SCPClient(ssh.get_transport())
    scp.put(bkp_path, recursive = True, remote_path = Remote_tar_path)
    scp.close()

    RemoteTarExtract = "tar -xvzf" + Remote_tar_path + "/" + filename

    print "RemoteTarCommand : %s " %(RemoteTarExtract)
#    quit()

    try:
        ssh.connect(ip, port=22, username = SSH_USERNAME, password = SSH_PASSWORD)
        ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(RemoteTarExtract)
    except Exception as e:
        print "SSH Connection Error : %r" %(e)

    if ssh_stdout:
        sys.stdout.write(ssh_stdout.read())
    if ssh_stderr:
        sys.stderr.write(ssh_stderr.read())
예제 #5
0
import paramiko
import scp

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect("web.sourceforge.net", username="", password="")
print '[+] Authenticating against web.sourceforge.net...'

scp = scp.SCPClient(ssh_client.get_transport())
scp.put('C:\Users\user\Desktop\password.txt')
print '[+] File is uploaded'
scp.close()
print '[+] Closing the socket'
import paramiko
import scp

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh_client.connect('web.sourceforge.net', username='******', password='******')

scp = scp.SCPClient(ssh_client.get_transport())

scp.put('path_to_file')
print '[+] File is uploaded.'

scp.close()