ftp seems to get a delayed reaction.

A

Antoon Pardon

I'm not sure if this is a python problem or something else.
I'm trying with the use of ftplib to get a dump on a remote machine.
The dump mirrors the directory structure but instead of the files
a bziped tar file is made and transferred.

While mirroring the directory structure I don't care to check which
directories are already present. I just try to make the directory
and catch the exception when it occurs. This worked fine until now.

I recently movade the script to a new computer and use a different
ftp server. Now it seems the error code for the ftp.mkd is received
by the storbinary later on.

This is the traceback:

Traceback (most recent call last):
File "ftpdump", line 141, in <module>
main()
File "ftpdump", line 133, in main
process(path)
File "ftpdump", line 90, in process
ftp.storbinary("STOR %s\n" % pj(cprt, "!ENTRY-tbz"), fl)
File "/usr/lib/python2.5/ftplib.py", line 425, in storbinary
self.voidcmd('TYPE I')
File "/usr/lib/python2.5/ftplib.py", line 246, in voidcmd
return self.voidresp()
File "/usr/lib/python2.5/ftplib.py", line 221, in voidresp
resp = self.getresp()
File "/usr/lib/python2.5/ftplib.py", line 216, in getresp
raise error_perm, resp
ftplib.error_perm: 521 "/tmpstor/rcpc42/bin" directory exists

This is part of the code:

# Somethings define somewhere above
#
# pj = os.path.join
# FTPProblem = ftplib.error_temp

while problem:
try:
ftp.storbinary("STOR %s\n" % pj(cprt, "!ENTRY-tbz"), fl)
fl.close()
problem = False
except FTPProblem:
warn ("reconnecting for %s\n" % cprt)
try:
ftp.quit()
except Exception:
pass
time.sleep(5)
ftpconnect()

So what seems to happen is that I call the ftp.storbinary and that
I get the mesg: ftplib.error_perm: 521 "/tmpstor/rcpc42/bin" directory exists
That I should have gotten while doing the ftp.mkd earlier.

Can someone shed some light on how to deal with this?
 
A

Antoon Pardon

I have managed to prune the script, so I can post it here:

==========================================================

from ftplib import FTP

bckrt = "/tmpstor/rcpc42"

def process():
print "making directory"
try:
ftp.mkd('ftp-tst')
print "mkdir succeeded"
except Exception, ErrMsg:
print "mkdir failed: %s" % ErrMsg
fl = open("tstfile")
print "storing file"
ftp.storbinary("STOR ftp-tst/ftp-file\n", fl)
fl.close()

ftp = FTP('ftphost', 'user', 'passwd')
ftp.set_pasv(False)
ftp.cwd(bckrt)

print "Doing once"
process()
print "Doing twice"
process()

----------------------------------------------------------
And this is the output:
==========================================================
Doing once
making directory
mkdir succeeded
storing file
Doing twice
making directory
mkdir failed: 500 '': command not understood.
storing file
Traceback (most recent call last):
File "ftptst", line 24, in <module>
process()
File "ftptst", line 14, in process
ftp.storbinary("STOR ftp-tst/ftp-file\n", fl)
File "/usr/lib/python2.5/ftplib.py", line 425, in storbinary
self.voidcmd('TYPE I')
File "/usr/lib/python2.5/ftplib.py", line 246, in voidcmd
return self.voidresp()
File "/usr/lib/python2.5/ftplib.py", line 221, in voidresp
resp = self.getresp()
File "/usr/lib/python2.5/ftplib.py", line 216, in getresp
raise error_perm, resp
ftplib.error_perm: 521 "/tmpstor/rcpc42/ftp-tst" directory exists
 
J

Jeremy.Chen

I have managed to prune the script, so I can post it here:

==========================================================

from ftplib import FTP

bckrt = "/tmpstor/rcpc42"

def process():
  print "making directory"
  try:
    ftp.mkd('ftp-tst')
    print "mkdir succeeded"
  except Exception, ErrMsg:
    print "mkdir failed: %s" % ErrMsg
  fl = open("tstfile")
  print "storing file"
  ftp.storbinary("STOR ftp-tst/ftp-file\n",  fl)
  fl.close()

ftp = FTP('ftphost', 'user', 'passwd')
ftp.set_pasv(False)
ftp.cwd(bckrt)

print "Doing once"
process()
print "Doing twice"
process()

----------------------------------------------------------
And this is the output:
==========================================================
Doing once
making directory
mkdir succeeded
storing file
Doing twice
making directory
mkdir failed: 500 '': command not understood.
storing file
Traceback (most recent call last):
  File "ftptst", line 24, in <module>
    process()
  File "ftptst", line 14, in process
    ftp.storbinary("STOR ftp-tst/ftp-file\n",  fl)
  File "/usr/lib/python2.5/ftplib.py", line 425, in storbinary
    self.voidcmd('TYPE I')
  File "/usr/lib/python2.5/ftplib.py", line 246, in voidcmd
    return self.voidresp()
  File "/usr/lib/python2.5/ftplib.py", line 221, in voidresp
    resp = self.getresp()
  File "/usr/lib/python2.5/ftplib.py", line 216, in getresp
    raise error_perm, resp
ftplib.error_perm: 521 "/tmpstor/rcpc42/ftp-tst" directory exists

ftp.storbinary("STOR ftp-tst/ftp-file\n", fl)
 
A

Antoon Pardon

ftp.storbinary("STOR ftp-tst/ftp-file\n", fl)

No that isn't the problem. The problem is the '\n' at the end of the
string. Having removed it, all worked fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top