Skip to content

Instantly share code, notes, and snippets.

@user0able
Last active October 28, 2023 20:09
Show Gist options
  • Save user0able/0d5fa98dceaa9ed12ade519d3c41537e to your computer and use it in GitHub Desktop.
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
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