Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FTP Question
#1
I'm fairly new to Python, and finding it to be very powerful thus far.

I have substituted the domain, username, password, and file names to preserve confidentiality.

I am looking to add somewhere in this code to be able to read and/or list the file names and determine if the script should continue to run or not. The parameters would be the date. So have the script run each day and if there's a package for that day, have the script execute a download of that file to my temp directory. Any insight would be appreciated!

Copy and pasting my code below:
import os import ftplib # log in to FTP Site ftp = ftplib.FTP("domain.com") ftp.login("username", "password") # Change directory ftp.cwd("Directory") # set up file name structure fnbase = "Package_" fnmid = "Version1.0_" fnend = "year_month_day.zip" # Select a location to save file download savedir = "C:/temp" os.chdir(savedir) # Execute download fn = fnbase + fnmid + fnend file = open(fn, "wb") ftp.retrbinary("RETR " + fn, file.write) file.close() print("Done")
Reply
#2
Do you have a specific question? For things like this, the usual thing is for you to give it a try and post a specific problem which is blocking you, and which if you were unblocked you'd be able to continue by yourself.
Reply


User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.