-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftp_lic.py
107 lines (96 loc) · 2.79 KB
/
ftp_lic.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ftplib
import parameters as gl
def get_lic(nif='*'):
directory = '/lic'
try:
ftp = ftplib.FTP(gl.ftp1[2],timeout=15)
ftp.login(gl.ftp1[0], gl.ftp1[1])
except Exception as err:
return False, 'Erro ao ligar ao FTP:' + str(err)
ftp.cwd(directory)
# print('dir',directory)
all_files = []
files = []
try:
all_files = ftp.nlst()
ftp.quit()
for n in all_files:
f = n.find(nif)
if f > -1:
files.append(n)
return True,ftp_to_list(files)
except Exception as resp:
print(str(resp))
return False, str(resp)
def ftp_to_list(mask):
f = []
dx = {}
for n in mask:
dx = {}
d = n.rfind('.rar')
a = n[:d]
d = a.find('-')
name = a[:d].replace('_',' ').title()
g = a[d+1:].split('-')
nif = g[0]
version = g[1]
f.append((name,nif,version,n))
hl = sorted(f, key=lambda student: student[2], reverse=True)
return hl
def get_lic_ftp(filename, t_file):
try:
session = ftplib.FTP(gl.ftp1[2], gl.ftp1[0], gl.ftp1[1], timeout=5)
session.cwd('/lic/')
lic_file = open('c:\\tmp\\' + t_file, 'wb')
session.retrbinary('RETR %s' % filename, lic_file.write)
session.quit()
return True, filename + ' OK!'
except Exception as resp:
return False, str(resp)
def make_file_name(f, v='2015.03'):
k = f.rfind('_')
f = f[:k]+'-'+f[k+1:]
return f.replace('.rar','-' + v + '.rar')
def ftp_get_list(mask):
f = []
dx = {}
for n in mask:
dx = {}
d = n.rfind('.rar')
a = n[:d]
d = a.find('-')
name = a[:d].replace('_',' ').title()
g = a[d+1:].split('-')
nif = g[0]
version = g[1]
f.append((name,nif,version,n))
hl = sorted(f, key=lambda student: student[2], reverse=True)
return hl
def driver_list(drv_type):
directory = '/drivers'
try:
ftp = ftplib.FTP(gl.ftp1[2], timeout=15)
ftp.login(gl.ftp1[0], gl.ftp1[1])
except Exception as err:
return False, 'Erro ao ligar ao FTP:' + str(err)
ftp.cwd(directory)
dataset = []
try:
all_files = ftp.nlst()
ftp.quit()
for n in all_files:
f = n.find(drv_type)
if f > -1:
display_name = n.replace(drv_type+'_', '')
display_name = display_name.replace('_',' ')
rp = display_name.rfind('.')
display_name = display_name[:rp]
dataset.append((display_name, n))
return True, dataset
except Exception as resp:
print(str(resp))
return False, str(resp)
if __name__ == '__main__':
pass