Post by calmarPost by Bram MoolenaarThat's right, when using ftp Aap only creates one level of directories.
The "mkdir" command of ftp doesn't have a flag to create directories
recursively. I haven't found a great need to handle it inside Aap.
Would need to detect that a "mkdir" fails because a directory is
missing. Can you see what error message the ftp server gives? Hmm,
this might differ between various ftp servers...
mkdir: Access failed: 550 aaa/ddd: No such file or directory
ftp can't access the not existing aaa folder, I think.
OK, it's not too difficult to try creating the directory recursively. I
wrote the code for it, but I can't test it, because the ftp server I
have access to does creates the directory recursivel already.
Apparently the "mkdir" command is implemented differently depending on
the ftp server used.
Please try the patch below with your ftp server.
Index: CopyMove.py
===================================================================
RCS file: /cvsroot/a-a-p/Exec/CopyMove.py,v
retrieving revision 1.49
diff -u -r1.49 CopyMove.py
--- CopyMove.py 30 May 2005 11:39:03 -0000 1.49
+++ CopyMove.py 17 Dec 2005 11:36:39 -0000
@@ -271,6 +271,32 @@
return ftp, msg
+def ftp_may_mkdir(recdict, error, ftp, destpath):
+ """If "error" indicates we failed to upload through ftp because the
+ directory doesn't exist try creating that directory. This works
+ recursively.
+ Return non-zero if the directory was created."""
+ if string.find(str(error), "No such file or dir") >= 0:
+ adir = os.path.dirname(destpath)
+ if len(adir) < len(destpath):
+ import ftplib
+ msg_info(recdict, _('Directory "%s" does not appear to exist, creating it...') % adir)
+ try:
+ ftp.mkd(adir)
+ except ftplib.all_errors, e:
+ # Maybe the upper directory doesn't exist, try creating it.
+ if ftp_may_mkdir(recdict, e, ftp, adir):
+ try:
+ ftp.mkd(adir)
+ except ftplib.all_errors, e:
+ msg_info(recdict, _('Could not create directory "%s"') % adir)
+ return 0
+ else:
+ return 0
+ return 1
+ return 0
+
+
def remote_copy_move(rpstack, recdict, copy, from_items, to_item,
optiondict, argexpand, errmsg = 0):
"""Copy or move command. Copy when "copy" is non-zero.
@@ -572,20 +598,9 @@
# If it looks like the directory doesn't exist, try
# creating it.
- if (error and string.find(str(error),
- "No such file or dir") >= 0):
- adir = os.path.dirname(destpath)
- if adir:
- import ftplib
- msg_info(recdict, _('Directory does not appear to exist, creating it...'))
- try:
- ftp.mkd(adir)
- except ftplib.all_errors, e:
- msg_info(recdict, _('Could not create directory'))
- pass
- else:
- msg_info(recdict, _('Directory created, attempt uploading again...'))
- error = store_file(ftp, fromfile, destpath)
+ if error and ftp_may_mkdir(recdict, error, ftp, destpath):
+ msg_info(recdict, _('Directory created, attempt uploading again...'))
+ error = store_file(ftp, fromfile, destpath)
if error:
msg = (_('Cannot upload "%s" to "%s": %s')
--
BEDEVERE: Oooooh!
LAUNCELOT: No "Aaaaarrrrrrggghhh ... " at the back of the throat.
BEDEVERE: No! "Oooooh!" in surprise and alarm!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- ***@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://www.ICCF.nl ///