Ticket #5441: 5441.3.diff

File 5441.3.diff, 2.7 KB (added by Adi Roiban, 10 years ago)
  • twisted/protocols/ftp.py

    === modified file 'twisted/protocols/ftp.py'
     
    10271027
    10281028
    10291029    def ftp_RETR(self, path):
     1030        """
     1031        This command causes the content of a file to be sent over the data
     1032        transfer channel. If the path is to a folder, an error will be raised.
     1033
     1034        @type path: C{str}
     1035        @param path: The path to the file which should be transferred over the
     1036        data transfer channel.
     1037
     1038        @rtype: L{Deferred}
     1039        @return: a L{Deferred} which will be fired when the transfer is done.
     1040        """
    10301041        if self.dtpInstance is None:
    10311042            raise BadCmdSequenceError('PORT or PASV required before RETR')
    10321043
     
    10711082            return d
    10721083
    10731084        def ebOpened(err):
    1074             if not err.check(PermissionDeniedError, FileNotFoundError, IsNotADirectoryError):
     1085            if not err.check(PermissionDeniedError, FileNotFoundError, IsADirectoryError):
    10751086                log.msg("Unexpected error attempting to open file for transmission:")
    10761087                log.err(err)
    10771088            if err.check(FTPCmdError):
  • twisted/test/test_ftp.py

    === modified file 'twisted/test/test_ftp.py'
     
    546546        return d
    547547
    548548
     549    def test_downloadFolder(self):
     550        '''When RETR is called for a folder, it will fail complaining that
     551        the path is a folder.
     552        '''
     553        #Make a directory in the current working directory
     554        self.dirPath.child('foo').createDirectory()
     555        # Login
     556        d = self._anonymousLogin()
     557        d.addCallback(self._makeDataConnection)
     558
     559        def retrFolder(downloader):
     560            downloader.transport.loseConnection()
     561            deferred = self.client.queueStringCommand('RETR foo')
     562            return deferred
     563        d.addCallback(retrFolder)
     564
     565        def failOnSuccess(result):
     566            raise AssertionError('Downloading a folder should not succeed.')
     567        d.addCallback(failOnSuccess)
     568
     569        def checkError(failure):
     570            failure.trap(ftp.CommandFailed)
     571            self.assertEqual(
     572                ['550 foo: is a directory'], failure.value.message)
     573            current_errors = self.flushLoggedErrors()
     574            self.assertEqual(
     575                0, len(current_errors),
     576                'No errors should be logged while downloading a folder.')
     577        d.addErrback(checkError)
     578        return d
     579
     580
    549581    def test_NLSTEmpty(self):
    550582        """
    551583        NLST with no argument returns the directory listing for the current