I am working on a script that will eventually run as scheduled via chron. This script will access ftp site and download most recent file added to directory. As I want this to be automatic, I wont have a file name to pass. How do I tell python which file to transfer?

Use urllib to fetch the ftp directory:

>>> a=urlopen('ftp://ftp.cs.stanford.edu/pub/cweb/')
>>> a=a.read()
>>> print a
drwxr-xr-x   3 ftp      users        4096 Oct 24  2006 .
drwxr-xr-x  49 sybase   sybase       4096 Dec 11  2008 ..
-rw-r--r--   1 ftp      users        4962 Dec 29  2003 Makefile
-rw-r--r--   1 ftp      users        4950 Feb 14  2002 Makefile~
-rw-r--r--   1 ftp      users        3270 Feb 14  2002 README
-rw-r--r--   1 ftp      users       61440 Oct  1  2003 albertus.tar

as you can see , this is giving me date of last modification as well as size. Use it to check which files are new.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.