/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/ftp.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-08 14:55:19 UTC
  • mfrom: (3530 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3532.
  • Revision ID: john@arbash-meinel.com-20080708145519-paqg4kjwbpgs2xmq
Merge bzr.dev 3530

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
 
90
90
    def __init__(self, base, _from_transport=None):
91
91
        """Set the base path where files will be stored."""
92
 
        assert base.startswith('ftp://') or base.startswith('aftp://')
 
92
        if not (base.startswith('ftp://') or base.startswith('aftp://')):
 
93
            raise ValueError(base)
93
94
        super(FtpTransport, self).__init__(base,
94
95
                                           _from_transport=_from_transport)
95
96
        self._unqualified_scheme = 'ftp'
178
179
            or 'no such dir' in s
179
180
            or 'could not create file' in s # vsftpd
180
181
            or 'file doesn\'t exist' in s
 
182
            or 'rnfr command failed.' in s # vsftpd RNFR reply if file not found
181
183
            or 'file/directory not found' in s # filezilla server
 
184
            # Microsoft FTP-Service RNFR reply if file not found
 
185
            or (s.startswith('550 ') and 'unable to rename to' in extra)
182
186
            ):
183
187
            raise errors.NoSuchFile(path, extra=extra)
184
188
        if ('file exists' in s):
306
310
            try:
307
311
                f.storbinary('STOR '+tmp_abspath, fp)
308
312
                self._rename_and_overwrite(tmp_abspath, abspath, f)
 
313
                self._setmode(relpath, mode)
309
314
                if bytes is not None:
310
315
                    return len(bytes)
311
316
                else:
347
352
            mutter("FTP mkd: %s", abspath)
348
353
            f = self._get_FTP()
349
354
            f.mkd(abspath)
 
355
            self._setmode(relpath, mode)
350
356
        except ftplib.error_perm, e:
351
357
            self._translate_perm_error(e, abspath,
352
358
                unknown_exc=errors.FileExists)
407
413
            conn = ftp.transfercmd(cmd)
408
414
            conn.sendall(text)
409
415
            conn.close()
410
 
            if mode:
411
 
                self._setmode(relpath, mode)
 
416
            self._setmode(relpath, mode)
412
417
            ftp.getresp()
413
418
        except ftplib.error_perm, e:
414
419
            self._translate_perm_error(e, abspath, extra='error appending',
428
433
        Only set permissions if the FTP server supports the 'SITE CHMOD'
429
434
        extension.
430
435
        """
431
 
        try:
432
 
            mutter("FTP site chmod: setting permissions to %s on %s",
433
 
                str(mode), self._remote_path(relpath))
434
 
            ftp = self._get_FTP()
435
 
            cmd = "SITE CHMOD %s %s" % (self._remote_path(relpath), str(mode))
436
 
            ftp.sendcmd(cmd)
437
 
        except ftplib.error_perm, e:
438
 
            # Command probably not available on this server
439
 
            warning("FTP Could not set permissions to %s on %s. %s",
440
 
                    str(mode), self._remote_path(relpath), str(e))
 
436
        if mode:
 
437
            try:
 
438
                mutter("FTP site chmod: setting permissions to %s on %s",
 
439
                    str(mode), self._remote_path(relpath))
 
440
                ftp = self._get_FTP()
 
441
                cmd = "SITE CHMOD %s %s" % (oct(mode),
 
442
                                            self._remote_path(relpath))
 
443
                ftp.sendcmd(cmd)
 
444
            except ftplib.error_perm, e:
 
445
                # Command probably not available on this server
 
446
                warning("FTP Could not set permissions to %s on %s. %s",
 
447
                        str(mode), self._remote_path(relpath), str(e))
441
448
 
442
449
    # TODO: jam 20060516 I believe ftp allows you to tell an ftp server
443
450
    #       to copy something to another machine. And you may be able
512
519
            paths = f.nlst(basepath)
513
520
        except ftplib.error_perm, e:
514
521
            self._translate_perm_error(e, relpath, extra='error with list_dir')
 
522
        except ftplib.error_temp, e:
 
523
            # xs4all's ftp server raises a 450 temp error when listing an empty
 
524
            # directory. Check for that and just return an empty list in that
 
525
            # case. See bug #215522
 
526
            if str(e).lower().startswith('450 no files found'):
 
527
                mutter('FTP Server returned "%s" for nlst.'
 
528
                       ' Assuming it means empty directory',
 
529
                       str(e))
 
530
                return []
 
531
            raise
515
532
        # If FTP.nlst returns paths prefixed by relpath, strip 'em
516
533
        if paths and paths[0].startswith(basepath):
517
534
            entries = [path[len(basepath)+1:] for path in paths]