-
Notifications
You must be signed in to change notification settings - Fork 0
/
_sftp.py
executable file
·45 lines (38 loc) · 1.13 KB
/
_sftp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
#############################################
#
# Libs
from _dutil import *
import paramiko
#############################################
class SFTP:
def end(self):
#doDebug(self.TAG+"Desconectando")
if self.sftp is not None:
self.sftp.close()
if self.transport is not None:
self.transport.close()
#def __del__(self):
# doDebug("DESTROY SFTP CONN")
def __init__(self, host, port, user, passwd, TAG=''):
self.transport = None
self.sftp = None
self.TAG = TAG
try:
#doDebug(TAG+"Conectando no servidor: "+host)
self.transport = paramiko.Transport((host, port))
except Exception, e:
raise Exception('Erro: '+str(e))
try:
#doDebug(TAG+"Realizando autenticacao user["+user+"] pass["+passwd+"]")
self.transport.connect(username=user, password=passwd)
except Exception, e:
self.end()
raise Exception('Erro: '+str(e))
try:
#doDebug(TAG+"Criando o cliente SFTP")
self.sftp = paramiko.SFTPClient.from_transport(self.transport)
except Exception, e:
self.end()
raise Exception('Erro: '+str(e))
################################################################################