-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathggg.py
More file actions
32 lines (25 loc) · 944 Bytes
/
ggg.py
File metadata and controls
32 lines (25 loc) · 944 Bytes
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
from ftplib import FTP
from configparser import ConfigParser
src = r"the path to your credentials and hostname"
config = ConfigParser()
config.read(src)
host = config["FTP"]["host"]
username = config["FTP"]["username"]
password = config["FTP"]["password"]
# Connect and list contents.
ftp = FTP(host=host)
ftp.login(user=username, passwd=password)
list_cont = ftp.nlst()
# The below will create a list form list_cont only containing the items we are concerned with.
# This is so that we can then sort the new list and always download the most recent item.
substr = "part of filename to filter for"
final_list = list(filter(lambda s: substr in s, list_cont))
final_list.sort()
file_to_get = final_list[-1]
# Download happens here:
def grab_file(fname):
print(f"Downloading {fname}")
ftp.retrbinary("RETR " + fname, open(fname, "wb").write, 2400)
print(f"Successfully downloaded {fname}")
ftp.quit()
grab_file(file_to_get)