Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -- coding: utf-8 --
- import paramiko
- class conectaSftp():
- def __init__(self, HOST, PORTA, USUARIO, SENHA):
- self.host = HOST
- self.porta = PORTA
- self.usuario = USUARIO
- self.senha = SENHA
- def conecta(self):
- try:
- self.transport = paramiko.Transport((self.host, self.porta))
- self.transport.connect(username=self.usuario, password=self.senha)
- self.sftp = paramiko.SFTPClient.from_transport(self.transport)
- except:
- print "error ao conectar"
- def exibirLstDiretorios(self):
- #dirlist on remote host
- dirlist = self.sftp.listdir('.')
- return dirlist
- def lerConteudoArquivo(self, endLocalArq):
- try:
- dadosArquivo =self.sftp.open(endLocalArq, 'r').read()
- except:
- print "Arquivo nao encontrado"
- return dadosArquivo
- def upload(self, local, remote):
- #(self, localpath, remotepath, callback=None, confirm=True)
- self.sftp.put(local, remote)
- def download(self, remote, local):
- self.sftp.get(remote, local)
- def close(self):
- if self.transport.is_active():
- self.sftp.close()
- self.transport.close()
- print"conexao fechada"
- return
- x = conectaSftp(HOST, PORTA, USUARIO, SENHA)
- x.conecta()
- #print x.exibirLstDiretorios()
- pastaServerArq = "/home/dyesten/testes/anotProjetoFacu.txt"
- pastaServ = "/home/dyesten/testes"
- pastaLocalArq = "C:\Users\dyesten\Desktop\teste.txt"
- pastaLocal = "C:\Users\dyesten\Desktop"
- x.download(pastaServerArq, pastaLocal)
- x.upload(pastaLocal, pastaServ)
- x.close()
Add Comment
Please, Sign In to add comment