What is happening with this program

John Machin machin_john_888 at hotmail.com
Wed Jul 18 18:02:25 EDT 2001


Kemp Randy-W18971 <Randy.L.Kemp at motorola.com> wrote in message news:<mailman.995478810.30770.python-list at python.org>...
> Can someone tell me what is happening here?  Is it saying my original
> directory is not present?  If not, can anyone tell me how to fix this
> program?  The program ran fine in windows, and I am enclosing:
> 1. Results of executing program on Solaris.
> 2. File on server where program is being executed
> 3. Program with IP and sign on information changed.
> 
> ------------------------> Results of executing program
> <---------------------------------------------------------------------------
> -----
> 
> pdsweb:/usr2/websoftware/pythonprograms> ./ftpclient.py
> tablespace.list,redologs.list,logfile.list,controlfile.list,dumpdest.list,us
[snip]> .ctl.Z,backup.controlfile,initpdsweb.ora,tnsnames.ora,listener.ora
> filename = filename

What's this? Is this meaningless output expected? Does this come under
your definition of "ran fine in windows"?

> 
> name = name

What's this? Is this ...

> 
> Traceback (most recent call last):
>   File "./ftpclient.py", line 16, in ?
>     ftp.storbinary("STOR " + name, open(filename, 'rb'))
>   File "/usr2/ActivePython-2.1/lib/python2.1/ftplib.py", line 371, in
> storbinary
>     conn = self.transfercmd(cmd)
>   File "/usr2/ActivePython-2.1/lib/python2.1/ftplib.py", line 296, in
> transfercmd
>     return self.ntransfercmd(cmd, rest)[0]
>   File "/usr2/ActivePython-2.1/lib/python2.1/ftplib.py", line 278, in
> ntransfercmd
>     resp = self.sendcmd(cmd)
>   File "/usr2/ActivePython-2.1/lib/python2.1/ftplib.py", line 229, in
> sendcmd
>     return self.getresp()
>   File "/usr2/ActivePython-2.1/lib/python2.1/ftplib.py", line 202, in
> getresp
>     raise error_perm, resp
> ftplib.error_perm: 553
> /usr2/websoftware/oraclebackupfiles/pdsweb/tablespace.list: No such file or
> directory.

"No such file or directory" is probably not very meaningful. According
to RFC 959, code 553 means "Requested action not taken. File name not
allowed." This may give you a better clue.

> pdsweb:/usr2/websoftware/pythonprograms>
> 
> -----------------> File on sending server
> <--------------------------------------------------------------------
> 
> pdsweb:/usr2/websoftware/oraclebackupfiles/pdsweb> ls
> backup.controlfile
[snip]
> usr2_pdswebdbfiles_oradata_pdsweb_users01.dbf.Z
> pdsweb:/usr2/websoftware/oraclebackupfiles/pdsweb> 
> 
> -------------------> Python program (with sensitive data changed to protect
> the innocent) <---------------------------------------------
> 
> #!/usr2/ActivePython-2.1/bin/python
> import string, os
> import ftplib
> import glob
> filename = os.path.join("usr2", "websoftware", "oraclebackupfiles",
> "pdsweb")

You started off on the right track here, using the os.path module
functions for portability ...

> listname =
> string.join(os.listdir('/usr2/websoftware/oraclebackupfiles/pdsweb'),',')

.. but were quickly seduced by the Dark Side; those hardwired slashes
are harbingers of doom ...

> print listname

Not relevant to your problem, but the above is susceptible to stepwise
refinement:
(1) listname =  string.join(os.listdir(filename),','); print listname
(2) print string.join(os.listdir(filename),',')
(3) print os.listdir(filename) # not identical, but good enough for
debugging

> 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/')

Those slashes again ...

> for filename in glob.glob('/usr2/websoftware/oraclebackupfiles/pdsweb/*'):

and again ...

>     name = string.split(filename, '\\')[-1]

Wwwhhhoooooopppsss!!!  A *back*slash ???? This *might* just explain
why it doesn't "run fine" on non-windows.

Try using os.path.split() for portability. When you RTFM and you find
that the FingM refers to "slash" instead of "path separator", you may
take some comfort from the fact that you are not alone in
non-portability :-)

However, try fixing the two following print statements first, and run
this again, so that you can see better what is happening.  Then change
to using os.path.split()

>     print "filename = " + 'filename' + "\n"

This can be "refined" to 
   print "filename = filename\n"
... perhaps not what you intended. Perhaps you are a recent convert
from some  language where " (quote) and ' (apostrophe) have different
meaning. Perhaps you meant to use ` (grave accent) instead of '
(apostrophe). You may like to try repr(x) instead of `x`.

>     print "name = " + 'name' + "\n"
>     ftp.storbinary("STOR " + name, open(filename, 'rb'))
> ftp.retrlines('LIST')  # list directory contents
> ftp.quit()

HTH,
John



More information about the Python-list mailing list