-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (73 loc) · 3.06 KB
/
main.py
File metadata and controls
82 lines (73 loc) · 3.06 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
'''
************************************************************************************
**
** AUTHOR(S):
** Leonel Nieto Lara
**
** TITLE:
** main.py
**
** DESCRIPTION:
** Script to transfer or download files with telnet and ftp
************************************************************************************
'''
from ftp import *
from telnet import *
if _name_ == "_main_":
args = parseArgs( sys.argv[ 1 : ] )
IPADDRESS = args.ip
PORT = args.port
USERNAME = args.username
PASSWORD = args.password
FILENAME = args.file
OPERATION = args.operation
AUTOMANUAL = args.AutoManual
COPY_ALL_FROM_VAR_TO_A2B = "cp /var/ftp/* /mnt/sdcard/A2B/"
COPY_ALL_FROM_A2B_TO_VAR = "cp /mnt/sdcard/A2B/* /var/ftp/"
Executable_Path = sys.argv[0]
folder_path = os.path.dirname(os.path.abspath(Executable_Path))
if OPERATION == "List":
transferfilesFTP = TransferFilesFTP( IPADDRESS, USERNAME, PASSWORD )
transferfilesFTP.connectFTP( )
transferfilesFTP.list_files( )
transferfilesFTP.disconnect( )
elif OPERATION == "Upload":
for ip in IPADDRESS:
print( f'Conecting to: {ip}' )
transferfilesFTP = TransferFilesFTP( ip, USERNAME, PASSWORD )
transferfilesFTP.connectFTP( )
if AUTOMANUAL == "Auto":
files_list = os.listdir(folder_path)
print( f'Lista de archivos: {files_list}' )
for autoFile in files_list:
if ( autoFile[-4:] != ".exe" ) and ( autoFile[-4:] != ".bat" ):
print(f"Transfering {autoFile} file")
transferfilesFTP.uploadFiles( autoFile )
else:
for file in FILENAME:
print(f"Transfering {file} file")
transferfilesFTP.uploadFiles( file )
open_sesion( ip, PORT, USERNAME, PASSWORD )
send_command( COPY_ALL_FROM_VAR_TO_A2B )
close_sesion( )
transferfilesFTP.disconnect( )
elif OPERATION == "Download":
currentPath = folder_path + "\\" + "DescargasFlex\\"
for ip in IPADDRESS:
transferfilesFTP = TransferFilesFTP( ip, USERNAME, PASSWORD )
transferfilesFTP.connectFTP( )
if "All" not in FILENAME:
open_sesion( ip, PORT, USERNAME, PASSWORD )
for file in FILENAME:
send_command( f"cp /mnt/sdcard/A2B/{file} /var/ftp/" )
transferfilesFTP.downloadFiles( file, currentPath )
close_sesion( )
else:
open_sesion( ip, PORT, USERNAME, PASSWORD )
send_command( COPY_ALL_FROM_A2B_TO_VAR)
close_sesion( )
filesFromFlex = transferfilesFTP.list_files( )
for file in filesFromFlex:
transferfilesFTP.downloadFiles( file, currentPath)
#LOGICA PARA SACAR TODOS LOS ARCHIVOS Y DESCARGARLOS
transferfilesFTP.disconnect( )