Last active
October 28, 2023 20:09
-
-
Save user0able/0d5fa98dceaa9ed12ade519d3c41537e to your computer and use it in GitHub Desktop.
Utilizando FTP=> recorre los archivos de una carpeta, los descarga, y los elimina
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ftplib | |
try: | |
from credentials import USER, PASSWORD, HOST, ROUTE | |
except ModuleNotFoundError: | |
USER = 'xxx' | |
PASSWORD = 'xxx' | |
HOST = '207.38.86.xx' | |
ROUTE = 'temporal' | |
def ftp_connect(HOST, USER, PASSWORD, ROUTE): | |
ftp = ftplib.FTP( | |
host=HOST, | |
user=USER, | |
passwd=PASSWORD | |
) | |
ftp.cwd(ROUTE) | |
files = ftp.nlst() | |
for file in files: | |
# download file: | |
with open(file, 'wb') as temp_file: | |
ftp.retrbinary('RETR %s' % file, temp_file.write) | |
ftp.delete(file) | |
ftp.quit() | |
ftp_connect( | |
HOST, | |
USER, | |
PASSWORD, | |
ROUTE | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment