65
65
class FtpStatResult(object):
66
def __init__(self, f, relpath):
67
def __init__(self, f, abspath):
68
self.st_size = f.size(relpath)
69
self.st_size = f.size(abspath)
69
70
self.st_mode = stat.S_IFREG
70
71
except ftplib.error_perm:
74
75
self.st_mode = stat.S_IFDIR
146
147
connection.login(user=user, passwd=password)
147
148
connection.set_pasv(not self.is_active)
149
# binary mode is the default
150
connection.voidcmd('TYPE I')
148
151
except socket.error, e:
149
152
raise errors.SocketConnectionError(self._host, self._port,
150
153
msg='Unable to connect to',
409
412
abspath = self._remote_path(relpath)
410
413
mutter("FTP appe (try %d) to %s", retries, abspath)
411
414
ftp = self._get_FTP()
412
ftp.voidcmd("TYPE I")
413
415
cmd = "APPE %s" % abspath
414
416
conn = ftp.transfercmd(cmd)
415
417
conn.sendall(text)
517
519
mutter("FTP nlst: %s", basepath)
518
520
f = self._get_FTP()
520
paths = f.nlst(basepath)
521
except ftplib.error_perm, e:
522
self._translate_perm_error(e, relpath, extra='error with list_dir')
523
except ftplib.error_temp, e:
524
# xs4all's ftp server raises a 450 temp error when listing an empty
525
# directory. Check for that and just return an empty list in that
526
# case. See bug #215522
527
if str(e).lower().startswith('450 no files found'):
528
mutter('FTP Server returned "%s" for nlst.'
529
' Assuming it means empty directory',
523
paths = f.nlst(basepath)
524
except ftplib.error_perm, e:
525
self._translate_perm_error(e, relpath,
526
extra='error with list_dir')
527
except ftplib.error_temp, e:
528
# xs4all's ftp server raises a 450 temp error when listing an
529
# empty directory. Check for that and just return an empty list
530
# in that case. See bug #215522
531
if str(e).lower().startswith('450 no files found'):
532
mutter('FTP Server returned "%s" for nlst.'
533
' Assuming it means empty directory',
538
# Restore binary mode as nlst switch to ascii mode to retrieve file
533
542
# If FTP.nlst returns paths prefixed by relpath, strip 'em
534
543
if paths and paths[0].startswith(basepath):
535
544
entries = [path[len(basepath)+1:] for path in paths]