0

I want to know if there is a way to download a file from my ftp server based on the date modified. For example, I have files for the entire month of June, but only want a file from June 15th. At the moment, I have my server up and running, and am able to connect my client and download a specific file e.g. "test.csv" but I would like to download a file according to the date modified. Is there a way to do this?

I am using Python 2 and Windows 10

code:

from ftplib import FTP
import os

host = "localhost"
port = 2121

ftp = FTP()
ftp.connect(host, port)
ftp.login("user", "12345")

filename = "test.csv"
directory = "randomdirectory"
if not os.path.exists(directory):
    os.makedirs(directory)


print("making dir")
# download file from ftp
path = os.path.join(directory,filename)
fil = open(path, 'wb')
ftp.retrbinary('RETR '+ filename, fil.write)
print("success?")

Thanks!

pgan16
  • 45
  • 4
  • There is a great discussion (with examples) describing how to obtain the time stamps of files on the server in the answers to this question: https://stackoverflow.com/questions/29026709/how-to-get-ftp-files-modify-time-using-python-ftplib – Rusty Widebottom Jul 08 '20 at 16:24
  • @RustyWidebottom thanks! – pgan16 Jul 08 '20 at 20:47

0 Answers0