-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFTP_V1.py
More file actions
119 lines (45 loc) · 1.24 KB
/
Copy pathFTP_V1.py
File metadata and controls
119 lines (45 loc) · 1.24 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
import ftplib
import os
#------------constants------------------
sites=[]
sites.append(['192.168.100.2','nicolas','nicolas'])
selected_site_index=0
site= sites[selected_site_index]
sub_dir= '' # '/sub-directory
file_report= "report.txt"
#-end------------constants---------------
site_url= site[0]
site_user= site[1]
site_pass= site[2]
report= os.path.join(os.path.curdir , file_report)
ftp = ftplib.FTP(site_url)
ftp.login(site_user, site_pass)
def clear_file_report():
if os.path.exists (report):
print("Removing the old report file")
os.remove(report)
else:
print("Creating a new report file")
append("FILE LIST")
def append(text, ):
if os.path.exists (report):
f = open(report, "a")
else:
f = open(report, "w")
f.write ("%s\b"%text)
f.close()
def process():
clear_file_report()
files = []
try:
files = ftp.dir()
except ftplib.error_perm as resp:
if str(resp) == "550 No files found":
append("")
else:
append(resp)
for f in files:
print("Writing:%s" % f)
append(f)
if __name__ == "__main__":
process()