I connect via FTP to the server and I make a list of what there is, and then I create a pattern to look for a file with a condition (* .bak),
if puerto=='21':
print('---->Entramos por el puerto 21')
# Hacemos la conexión Ftp a servidor
ftp = FTP(servidor)
# Hacemos el login de usuario y passwd,
ftp.login(user=usuario, passwd=contrasena)
# La función FTP.cwd() es utilizada para cambiar de directorio o carpeta remota
ftp.cwd(rutaServer)
# Listamos y lo guardamos en la variable listadoFich
listadoFich=ftp.retrlines('LIST')
print(listadoFich)
# Generamos un bucle para recorrer listadoFich e intentamos y buscar por patrón e imprimir por pantalla.
No necesariamente el archivo tiene .patron , el nombre del archivo puede tener patron a la mitad de su nombre como sale en la foto mas abajo
for fichero in listadoFich:
print('patron -----> '+ patron )
if fichero.endswith(patron):
print('match------->' + patron)
else:
print('NO match------->' + patron)
# cerramos la conexion
ftp.close()
The problem is that when you scroll through the file with the for loop it does not list any match, with the endswith you do not find anything, any error?