newbie needs a little help... trying to write an ftp script.

google account mynews44 at yahoo.com
Mon Jul 28 14:40:48 EDT 2003


hiya,

I am a network admin type person who has (after a bit of research and
a couple of dabblings) decided that python is the language for me.

I have read through learning python,  nad it has managed to give me a
great basis for the things I have done previously (regex manipulation
of config files,  mostly.  I got a great application built fairly
quickly that would parse an apache config,  add a VirtualHost entry, 
sort it alphabetically and sighup the deamon) but my present task is
something that doesn't really get covered in this most excellent tome.


I want to create an ftp script that will (from a windows2000 host) log
into an ftp server,  change down one directory, download specific
files from this directory (wildcard passing...?) and then log out. 
Once it has completed this task,  it should email someone to inform
them of completion status, perhaps including the output of the ftp
session.

I can't imagine that it would be too hard,  but I don't see anything
afer a google search that will give me any pointers so I was hoping I
might get some in response to this post.   I have found the ftplib, 
and the info on the python.org docs. I am needing a pointer on the
syntax,  or a bit of a (non-programmer) translation with what they
mean.

The docs suggest that I could do something like....

import ftplib
	
ftp = ftplib.FTP('172.30.30.30')  # This is wrong,  somehow...?
ftp.login(user,pass)
ftp.retrlines('LIST')  # I believe it might need to be
ftp.retrlines('ls -al')
ftp.sendcmd('prompt')
ftp.cwd('folder')
ftp.retrbinary(retr *tgz)
ftp.quit()



Or that maybe I could define a new class with something like this:

class HandleFTP(ftplib.FTP):
(I am not sure what would follow here,   but I'm thinking it might be
what I want.   This way I get to define a few functions within my own
class,  and these can capture all the server output to a text file, 
for later emailling.)

	

Basically, I am getting errors with the first line somehow,  and I am
not sure what to replace it with.

Some of these things,  the docs tell me they return a string.  Does
that mean I should initialise a string for them?  Would they not work
if that isn't happening,  or would the output just end up in
/dev/null?



Thanks for looking!

Googleboy




More information about the Python-list mailing list