FTP program works -- now how do I send the directory over?

Steve Holden sholden at holdenweb.com
Thu Jul 5 10:12:45 EDT 2001

"Kemp Randy-W18971" <Randy.L.Kemp at motorola.com> wrote in message
news:mailman.994341308.26018.python-list at python.org...
> I seem to be getting the listing of what's on my d drive in windows,
rather then the binary contents.  Here is what I do (the server id changed
to protect the innocent:
> ------------------------> Step 1
> Execute this program in Windoze
> import string, os
> import ftplib
> import glob
> filename = os.path.join("d:", "programsPython", "outdata3.txt")
> listname = string.join(os.listdir('d:\programsPython'),',')
> print listname
> ftp = ftplib.FTP('') #specify host
> ftp.connect() # defaults to port 21, check docs for further options
> ftp.login(user=goofy',passwd='elmer',acct='fudd)   # user info
> ftp.cwd('/usr2/ecadtesting/tarbackups')
> for filename in glob.glob('d:\programsPython\*'):
>     ftp.storbinary("STOR " + filename, open(filename, 'rb'))
> ftp.retrlines('LIST')  # list directory contents
> ftp.quit()
> -----------------> Step 2 <-----------------------------------------------
> List the directory contents in Unix
> ee110:/usr2/ecadtesting/tarbackups> ls
> d:\programsPython\CE H2-102000 Usage Mentor1.txt
[ ... ]
> d:\programsPython\testmail.py
> ee110:/usr2/ecadtesting/tarbackups>
> -----------------> Problem <--------------------------------------
> Why do I get the text d:\programsPython\filename?
> How should I change the program to get the actual files sent over?
The problem is your current directory context. If you *just* want to deal
with simple paths, try changing

    for filename in glob.glob('d:\programsPython\*'):


    for filename in glob.glob("*"):

That way your program changes its directory context to the directory
containing the files you want to transfer, so you can refer to them as
simple filenames rather than as a path.

Another way yould be to omit the os.chdir() but run the program in the
directory whose files you want to transfer.


More information about the Python-list mailing list