FTP win32 program

Acid none at nospam.net
Tue Jul 24 18:52:33 EDT 2001


"Steve Williams" <stevewilliams at wwc.com> wrote in message
news:3B5CF72B.E810465F at wwc.com...
> Acid wrote:
>
> > I am trying to write simple program with Python to connect to an ftp,
> > list, download a file(s) etc...
> >
> > I am running this under Win2K professional with Python 2.1:
> >
> > [snip]
>
> > I start the Python Gui, then New Window, put the above script in, then
> > save, then Run Script.  It returns:
> >
> >  File "C:/Python21/download.py", line 2
> >     from ftplib import FTP
> >     ^
> > SyntaxError: invalid syntax
> >
> > What's the trick to get this working under Win32?
> >
>
> That caret is in a suspicious place.  How are you putting the script in the
> New Window?  Cut and paste?  Check for random leading whitespace.
>
> Anyway, don't use
>
>     'from ftplib import FTP'
>
> even though the code itself and Beasley give that as their example,  because
> you'll have trouble catching exceptions.  And you will definitely want to
> catch exceptions with ftp.
>
> Use something like
>
> #=============================
> import ftplib
>
> #Connect to host
> try:
>     ftp = ftplib.FTP('x,y,z')
> except ftplib.all_errors, e:
>     print e
>     . . . #punt
>
> #Change working directory
> try:
>     ftp.sendcmd('CWD /misc'))
> except ftplib.all_errors, e:
>    print e
>    . . . #punt
>
> #List the directory
> try:
>     ftp.retrlines('LIST')
> except ftplib.all_errors, e:
>   print e
>    . . . #punt
> #=========================
>
> instead.
>
> I know the verb 'catch' is not Pythonic, but . . .
>
>
>

Well, that bombed out also with some crazy errors.

I would rather write this in C so I can just make an executable for the computer
challenged employees who can't perform an ftp download everyday.  That way it
will run on all WIN32 platforms etc..make life easy for them.

The plan was to write this to check for the current day from the system then go
out and ftp the appropriate files for that day and dump it in a directory for
them with just the click of a few buttons.

Thanks for the input...

Keith





More information about the Python-list mailing list