Bug fix. Wrong error code.

This commit is contained in:
madmaurice 2015-06-28 23:50:23 +02:00
parent cef5cc634a
commit 998cf32353

View file

@ -136,6 +136,9 @@ class Directory(FSNode):
return f return f
return None return None
def add_file(self,f):
self.files.append(f)
class File(FSNode): class File(FSNode):
def __init__(self,name,owner="nobody",group="nobody",rights=384,size=4096, content=None): def __init__(self,name,owner="nobody",group="nobody",rights=384,size=4096, content=None):
FSNode.__init__(self, name=name, owner=owner, group=group,rights=rights, size=size, iun=1) FSNode.__init__(self, name=name, owner=owner, group=group,rights=rights, size=size, iun=1)
@ -259,7 +262,7 @@ class QuitMessage(FTPMessage):
class CommandNotImplementedMessage(FTPMessage): class CommandNotImplementedMessage(FTPMessage):
''' Message sent to client when command not implemented''' ''' Message sent to client when command not implemented'''
def __init__(self): def __init__(self):
FTPMessage.__init__(self,"501","Command not implemented") FTPMessage.__init__(self,"502","Command not implemented")
class InvalidCommandMessage(FTPMessage): class InvalidCommandMessage(FTPMessage):
'''Message sent to client when server received message it didn't understand''' '''Message sent to client when server received message it didn't understand'''
@ -286,6 +289,11 @@ class WelcomeMessage(FTPMessage):
def __init__(self): def __init__(self):
FTPMessage.__init__(self,"220","FTP Server ready") FTPMessage.__init__(self,"220","FTP Server ready")
class FileActionCompletedMessage(FTPMessage):
'''Message sent to client after file action has been completed'''
def __init__(self):
FTPMessage.__init__(self,"250","Requested file action okay, completed.")
class EnteringPassiveModeMessage(FTPMessage): class EnteringPassiveModeMessage(FTPMessage):
def __init__(self,(ip,port)): def __init__(self,(ip,port)):
addr = ip.split(".") addr = ip.split(".")
@ -403,6 +411,17 @@ class RetrieveHandler:
self.node.send_content(socket) self.node.send_content(socket)
self.handler.send( EndFileRetrieve() ) self.handler.send( EndFileRetrieve() )
class VoidStoreHandler:
def __init__(self, handler):
self.handler = handler
def handle(self, socket):
data = socket.recv(1024)
while len(data) != 0:
data = socket.recv(1024)
self.handler.send( FileActionCompletedMessage() )
# CommandHandler classes # CommandHandler classes
class CommandHandler: class CommandHandler:
cmd = None cmd = None
@ -494,9 +513,17 @@ class RenameToCommandHandler(ForbiddenCommandHandler):
cmd = "RNTO" cmd = "RNTO"
log = "Attempt to rename to %s" log = "Attempt to rename to %s"
class StoreCommandHandler(ForbiddenCommandHandler): class StoreCommandHandler(CommandHandler):
cmd = "STOR" cmd = "STOR"
log = "Attempt to store file %s" def process(self, handler, message):
node = handler.get_node(message.parameter)
if node is None or node.is_file():
if handler.runDataConnection( VoidStoreHandler() ):
handler.log( "Writing file %s (voided)" )
else:
handler.send( UnableToBuildConnectionMessage() )
else:
handler.send( OperationNotPermittedMessage() )
class RetrieveCommandHandler(CommandHandler): class RetrieveCommandHandler(CommandHandler):
cmd = "RETR" cmd = "RETR"