What is happening with this program
Nick Mathewson
9nick9m at alum.mit.edu
Wed Jul 18 16:24:35 EDT 2001
On Wed, 18 Jul 2001 12:52:08 -0500,
Kemp Randy-W18971 <Randy.L.Kemp at motorola.com> wrote:
>#!/usr2/ActivePython-2.1/bin/python
>import string, os
>import ftplib
>import glob
>filename = os.path.join("usr2", "websoftware", "oraclebackupfiles", "pdsweb")
This value above is never used.
>listname = string.join(
> os.listdir('/usr2/websoftware/oraclebackupfiles/pdsweb'),',')
Neither is this one, unless the print below is intentional.
>print listname
>ftp = ftplib.FTP('999.999.999.999') #specify host
>ftp.connect() # defaults to port 21, check docs for further options
>ftp.login(user='fudd',passwd='elmer',acct='looney') # user info
>ftp.cwd('/usr2/pdsweb/oraclebackupfiles2/pdsweb/')
>
>for filename in glob.glob('/usr2/websoftware/oraclebackupfiles/pdsweb/*'):
It looks like you could use "glob.glob(filename)"
> name = string.split(filename, '\\')[-1]
This line above is your error: you're splitting on '\\' (which windows
uses as a directory separator). Unix uses '/'. Instead, try:
name = os.path.split(filename)[1]
> print "filename = " + 'filename' + "\n"
> print "name = " + 'name' + "\n"
These lines don't do anything useful. Did you mean to use `backquotes`?
Also, the "\n" is probably unnecessary, unless you mean to generate an
extra newline here.
> ftp.storbinary("STOR " + name, open(filename, 'rb'))
>ftp.retrlines('LIST') # list directory contents
>ftp.quit()
Suggested rewrite:
--------------------------------------------------
#!/usr2/ActivePython-2.1/bin/python
import string, os, ftplib, glob
localpath = os.path.join("usr2", "websoftware", "oraclebackupfiles", "pdsweb")
ftppath = '/usr2/pdsweb/oraclebackupfiles2/pdsweb/'
localfiles = os.listdir(localpath)
#print localfiles
ftp = ftplib.FTP('999.999.999.999') #specify host
ftp.connect() # defaults to port 21, check docs for further options
ftp.login(user='fudd',passwd='elmer',acct='looney') # user info
ftp.cwd('/usr2/pdsweb/oraclebackupfiles2/pdsweb/')
for localfile in localfiles:
fullname = os.path.join(localpath, localfile)
ftp.storbinary("STOR " + localfile, open(fullname, 'rb'))
ftp.retrlines('LIST') # list directory contents
ftp.quit()
--------------------------------------------------
HTH,
--
Nick Mathewson <9 nick 9 m at alum dot mit dot edu>
Remove 9's to respond. No spam.
More information about the Python-list
mailing list