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


Messages In This Thread
FTP Question - by AlexTeran - Jun-24-2019, 09:14 PM
RE: FTP Question - by micseydel - Jun-24-2019, 09:53 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020