[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/FTP - FileProducer.py:1.1.2.1 FTPServerChannel.py:1.1.2.5
Stephan Richter
srichter@cbu.edu
Wed, 3 Apr 2002 06:30:05 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Server/FTP
In directory cvs.zope.org:/tmp/cvs-serv1082/lib/python/Zope/Server/FTP
Modified Files:
Tag: Zope3-Server-Branch
FTPServerChannel.py
Added Files:
Tag: Zope3-Server-Branch
FileProducer.py
Log Message:
More work on FTP. I am trying to get the file transfer to work.
=== Added File Zope3/lib/python/Zope/Server/FTP/FileProducer.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: FileProducer.py,v 1.1.2.1 2002/04/03 11:29:34 srichter Exp $
"""
class FileProducer:
""" """
block_size = 16384
def __init__ (self, server, dc, fd):
self.fd = fd
self.done = 0
def more (self):
if self.done:
return ''
else:
block = self.fd.read (self.block_size)
if not block:
self.fd.close()
self.done = 1
return block
=== Zope3/lib/python/Zope/Server/FTP/FTPServerChannel.py 1.1.2.4 => 1.1.2.5 ===
from FTPCommandParser import FTPCommandParser
from FTPTask import FTPTask
+from FileProducer import FileProducer
from IFTPCommandHandler import IFTPCommandHandler
from PassiveAcceptor import PassiveAcceptor
@@ -156,11 +157,13 @@
def cmd_cwd (self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
- if self.server.filesystem.exists(args):
- self.cwd = args
+ path = os.path.join(self.cwd, args)
+ path = os.path.normpath(path)
+ if self.server.filesystem.exists(path):
+ self.cwd = path
self.reply(250, 0, 'CWD')
else:
- self.reply (550, 1, args)
+ self.reply (550, 1, path)
def cmd_dele(self, args):
@@ -317,18 +320,24 @@
if not args:
self.reply(550, 0, 'RETR')
else:
- if not self.server.filesystem.isfile(args):
+ # Get the right source path.
+ if args.startswith('/'):
+ path = args
+ else:
+ path = os.path.join(self.cwd, args)
+
+ if not self.server.filesystem.isfile(path):
#self.log_info ('checking %s' % file)
- self.reply(550, 2, args)
+ self.reply(550, 2, path)
else:
try:
# FIXME: for some reason, 'rt' isn't working on win95
mode = 'r'+self.type_mode_map[self.transfer_mode]
- fd = self.open(args, mode)
+ fd = self.server.filesystem.open(path, mode)
except IOError, why:
self.reply(553, 0, repre(why))
return
- self.reply(150, 1, (self.type_map[self.current_mode], file) )
+ self.reply(150, 1, (self.type_map[self.transfer_mode], path) )
self.createXmitChannel()
if self.restart_position:
@@ -342,7 +351,7 @@
self.restart_position = 0
self.client_dc.push_with_producer (
- file_producer (self, self.client_dc, fd)
+ FileProducer(self.server, self.client_dc, fd)
)
self.client_dc.close_when_done()
@@ -471,6 +480,7 @@
else:
dir = path_args[0]
+ dir = os.path.join(self.cwd, dir)
return self.listdir(dir, long)