[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/FTP - FTPCommandParser.py:1.1.2.3 FTPServerChannel.py:1.1.2.7 FTPStatusMessages.py:1.1.2.4 IFTPCommandHandler.py:1.1.2.2
Stephan Richter
srichter@cbu.edu
Wed, 3 Apr 2002 09:38:02 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Server/FTP
In directory cvs.zope.org:/tmp/cvs-serv20611/FTP
Modified Files:
Tag: Zope3-Server-Branch
FTPCommandParser.py FTPServerChannel.py FTPStatusMessages.py
IFTPCommandHandler.py
Log Message:
Okay, I just added rename functionality to the server, which means that the
new version of the FTP server handles now more commands than the old one!
=== Zope3/lib/python/Zope/Server/FTP/FTPCommandParser.py 1.1.2.2 => 1.1.2.3 ===
self.completed = 1
line = self.inbuf.strip()
- print line
self.parseLine(line)
return len(s)
=== Zope3/lib/python/Zope/Server/FTP/FTPServerChannel.py 1.1.2.6 => 1.1.2.7 ===
self.client_dc = None
- self.user_name = None
- self.user_password = None
-
self.transfer_mode = 'a'
self.passive_mode = 0
self.cwd = '/'
- # XXX: For debugging
- self.user = self.server.auth_source.user_class('foo')
- # self.user = self.server.auth_source.anonymous_user
-
+ self._rnfr = None
+
self.username = ''
self.password = ''
+ self.authenticated = 0
self.reply(220, 0, self.server.server_name)
@@ -105,8 +101,8 @@
assert isinstance(command, FTPCommandParser)
cmd = command.cmd
m = 'cmd_' + cmd.lower()
- if ( self.user is self.server.auth_source.anonymous_user and
- m not in ('cmd_user', 'cmd_pass')):
+ if ( not self.authenticated and
+ m not in ('cmd_user', 'cmd_pass', 'cmd_quit')):
# The user is not logged in, therefore don't allow anything
self.reply(530, 1)
@@ -132,7 +128,6 @@
self.end_task(0)
-
############################################################
# Implementation methods for interface
# Zope.Server.FTP.IFTPCommandHandler
@@ -177,10 +172,10 @@
path = self._generatePath(args)
try:
- self.server.filesystem.unlink(file)
+ self.server.filesystem.unlink(path)
self.reply(250, 0, 'DELE')
except:
- self.reply(550, 4)
+ self.reply(550, 6)
else:
self.reply(550, 2, file)
@@ -209,10 +204,13 @@
def cmd_mdtm(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
- if not self.server.filesystem.isfile (args):
- self.reply(550, 3, filename)
+ path = self._generatePath(args)
+ if not self.server.filesystem.isfile(path):
+ self.reply(550, 3, path)
else:
- mtime = time.gmtime(self.server.filesystem.stat(args)[stat.ST_MTIME])
+ mtime = time.gmtime(
+ self.server.filesystem.stat(path)[stat.ST_MTIME]
+ )
self.reply(213, 0, (mtime[0], mtime[1], mtime[2],
mtime[3], mtime[4], mtime[5]) )
@@ -267,8 +265,9 @@
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
self.password = args
auth = self.server.auth_source
- self.user = auth.authenticate(self.username, self.password)
- if self.user is not self.server.auth_source.anonymous_user:
+ self.authenticated, message = auth.authenticate(self.username,
+ self.password)
+ if self.authenticated:
self.reply(230)
else:
self.reply(530, 2)
@@ -280,8 +279,6 @@
pc = self.newPassiveAcceptor()
self.client_dc = None
port = pc.addr[1]
- # XXX: Very useful for testing
- print port
ip_addr = pc.control_channel.getsockname()[0]
self.reply(227, args=( ','.join(ip_addr.split('.')),
port/256,
@@ -290,17 +287,20 @@
def cmd_port(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
- info = string.split (args, ',')
- ip = string.join (info[:4], '.')
- port = int(info[4])*256 + int(info[5])
-
- # how many data connections at a time?
- # I'm assuming one for now...
- # XXX: we should (optionally) verify that the
- # ip number belongs to the client. [wu-ftpd does this?]
- self.client_addr = (ip, port)
- self.reply (200, args=('PORT',))
+ try:
+ info = args.split(',')
+ ip = '.'.join(info[:4])
+ port = int(info[4])*256 + int(info[5])
+ # how many data connections at a time?
+ # I'm assuming one for now...
+ # XXX: we should (optionally) verify that the
+ # ip number belongs to the client. [wu-ftpd does this?]
+ self.client_addr = (ip, port)
+ self.reply(200, 0, 'PORT')
+ except:
+ return self.reply(550, 0, 'PORT')
+
def cmd_pwd(self, args):
@@ -314,7 +314,7 @@
self.close_when_done()
- def cmd_retr (self, args):
+ def cmd_retr(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
if not args:
self.reply(550, 0, 'RETR')
@@ -351,7 +351,7 @@
self.client_dc.close_when_done()
- def cmd_rest (self, args):
+ def cmd_rest(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
try:
pos = int(args)
@@ -367,7 +367,6 @@
self.reply(500, 0, 'RMD')
else:
path = self._generatePath(args)
- print path
try:
self.server.filesystem.rmdir(path)
self.reply(250, 0, 'RMD')
@@ -375,6 +374,29 @@
self.reply(550, 7)
+ def cmd_rnfr(self, args):
+ 'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
+ path = self._generatePath(args)
+ if self.server.filesystem.exists(path):
+ self._rnfr = path
+ self.reply(350, 1)
+ else:
+ self.reply(550, 2, path)
+
+
+ def cmd_rnto(self, args):
+ 'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
+ path = self._generatePath(args)
+ if self._rnfr is None:
+ self.reply(560, 1)
+ try:
+ self.server.filesystem.rename(self._rnfr, path)
+ self.reply(250, 0, 'RNTO')
+ except:
+ self.reply(560, 0, (self._rnfr, rnto))
+ self._rnfr = None
+
+
def cmd_size(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
path = self._generatePath(args)
@@ -385,7 +407,7 @@
self.server.filesystem.stat(path)[stat.ST_SIZE])
- def cmd_stor (self, args, mode='wb'):
+ def cmd_stor(self, args, mode='wb'):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
if not args:
self.reply(550, 0, 'STOR')
=== Zope3/lib/python/Zope/Server/FTP/FTPStatusMessages.py 1.1.2.3 => 1.1.2.4 ===
"'%s' is the current directory.",),
331: ('Password required',),
- 350: ('Restarting at %d. Send STORE or RETRIEVE to initiate transfer.',),
+ 350: ('Restarting at %d. Send STORE or RETRIEVE to initiate transfer.',
+ 'File exists, ready for destination.',),
425: ("Can't build data connection",),
426: ('Connection closed; transfer aborted.',),
500: ("'%s': command not understood.",),
@@ -61,6 +62,7 @@
'Could not open file for writing: %s',
'Restart on STOR not yet supported',),
- 599: ("Unknown type '%s'.",),
+ 560: ('Could not rename %s to %s.',
+ 'No source filename specify. Call RNFR first.',),
}
=== Zope3/lib/python/Zope/Server/FTP/IFTPCommandHandler.py 1.1.2.1 => 1.1.2.2 ===
"""
- def cmd_abor():
+ def cmd_abor(args):
"""Abort operation. No read access required.
"""
- def cmd_appe(filename, mode):
+ def cmd_appe(args):
"""Append to a file. Write access required.
"""
- def cmd_cdup():
+ def cmd_cdup(args):
"""Change to parent of current working directory.
"""
- def cmd_cwd():
+ def cmd_cwd(args):
"""Change working directory.
"""
- def cmd_dele():
+ def cmd_dele(args):
"""Delete a file. Write access required.
"""
- def cmd_help():
+ def cmd_help(args):
"""Give help information. No read access required.
"""
- def cmd_list(path, match_pattern, long=1, recursive=0):
+ def cmd_list(args):
"""Give list files in a directory.
"""
- def cmd_mdtm(filename):
+ def cmd_mdtm(args):
"""Show last modification time of file.
Example output: 213 19960301204320
"""
- def cmd_mkd(path):
+ def cmd_mkd(args):
"""Make a directory. Write access required.
"""
- def cmd_mode(type):
+ def cmd_mode(args):
"""Set file transfer mode. No read access required. Obselete.
"""
- def cmd_nlst(path, match_pattern, long=0, recursive=0):
+ def cmd_nlst(args):
"""Give name list of files in directory.
"""
- def cmd_noop():
+ def cmd_noop(args):
"""Do nothing. No read access required.
"""
- def cmd_pass(password):
+ def cmd_pass(args):
"""Specify password.
"""
- def cmd_pasv():
+ def cmd_pasv(args):
"""Prepare for server-to-server transfer. No read access required.
"""
- def cmd_port(ip, port):
+ def cmd_port(args):
"""Specify data connection port. No read access required.
"""
- def cmd_pwd():
+ def cmd_pwd(args):
"""Print the current working directory.
"""
- def cmd_quit():
+ def cmd_quit(args):
"""Terminate session. No read access required.
"""
- def cmd_rest(position):
+ def cmd_rest(args):
"""Restart incomplete transfer.
"""
- def cmd_retr(filename):
+ def cmd_retr(args):
"""Retrieve a file.
"""
- def cmd_rmd(path):
+ def cmd_rmd(args):
"""Remove a directory. Write access required.
"""
- def cmd_rnfr(filename):
+ def cmd_rnfr(args):
"""Specify rename-from file name. Write access required.
"""
- def cmd_rnto(filename):
+ def cmd_rnto(args):
"""Specify rename-to file name. Write access required.
"""
- def cmd_size(filename):
+ def cmd_size(args):
"""Return size of file.
"""
- def cmd_stat(filename):
+ def cmd_stat(args):
"""Return status of server. No read access required.
"""
- def cmd_stor(filename, mode):
+ def cmd_stor(args):
"""Store a file. Write access required.
"""
- def cmd_stru(type):
+ def cmd_stru(args):
"""Set file transfer structure. Obselete."""
- def cmd_syst():
+ def cmd_syst(args):
"""Show operating system type of server system.
No read access required.
@@ -143,11 +143,11 @@
500 'SYST': command not understood. (SVR4)
"""
- def cmd_type(type, byte_size):
+ def cmd_type(args):
"""Specify data transfer type. No read access required.
"""
- def cmd_user(username):
+ def cmd_user(args):
"""Specify user name. No read access required.
"""