示例#1
0
    def ftp_PASV(self):
        if self.dtpFactory is not None:
            # cleanupDTP sets dtpFactory to none.  Later we'll do
            # cleanup here or something.
            self.cleanupDTP()
        self.dtpFactory = SaferDTPFactory(pi=self)
        self.dtpFactory.setTimeout(self.dtpTimeout)
        self.dtpPort = self.getDTPPort(self.dtpFactory)

        host = self.transport.getHost().host
        port = self.dtpPort.getHost().port
        self.reply(ftp.ENTERING_PASV_MODE, (ftp.encodeHostPort(host, port)))
示例#2
0
    def ftp_PASV(self):
        if self.dtpFactory is not None:
            # cleanupDTP sets dtpFactory to none.  Later we'll do
            # cleanup here or something.
            self.cleanupDTP()
        self.dtpFactory = SaferDTPFactory(pi=self)
        self.dtpFactory.setTimeout(self.dtpTimeout)
        self.dtpPort = self.getDTPPort(self.dtpFactory)

        host = self.transport.getHost().host
        port = self.dtpPort.getHost().port
        self.reply(ftp.ENTERING_PASV_MODE, (ftp.encodeHostPort(host, port)))
示例#3
0
 def testPORTCannotConnect(self):
     self._anonymousLogin()
     port = reactor.listenTCP(0, protocol.Factory(), interface='127.0.0.1')
     portNum = port.getHost().port
     d = port.stopListening()
     if d is not None:
         wait(d)
     cmd = 'PORT ' + ftp.encodeHostPort('127.0.0.1', portNum)
     d = self.client.queueStringCommand(cmd)
     self.failUnlessEqual(
         ["425 Can't open data connection."],
         self._waitForCommandFailure(d)
     )
示例#4
0
 def ftp_PASV(self):
     #raise None
     if self.dtpFactory is not None:
         self.cleanupDTP()
     self.dtpFactory = ftp.DTPFactory(pi=self)
     self.dtpFactory.setTimeout(self.dtpTimeout)
     self.dtpPort = self.getDTPPort(self.dtpFactory)
     #print "dtp port", self.dtpPort   
     host = self.transport.getHost().host
     port = self.dtpPort.getHost().port
     self.reply(ftp.ENTERING_PASV_MODE, ftp.encodeHostPort(host, port))
     #self.dtpFactory.deferred.addCallback(lambda ign: None)
     return 
示例#5
0
 def _makeDataConnection(self):
     deferred = defer.Deferred()
     class DataFactory(protocol.ServerFactory):
         protocol = _BufferingProtocol
         def buildProtocol(self, addr):
             p = protocol.ServerFactory.buildProtocol(self, addr)
             reactor.callLater(0, deferred.callback, p)
             return p
     dataPort = reactor.listenTCP(0, DataFactory(), interface='127.0.0.1')
     self.dataPorts.append(dataPort)
     cmd = 'PORT ' + ftp.encodeHostPort('127.0.0.1', dataPort.getHost().port)
     responseLines = wait(self.client.queueStringCommand(cmd))
     downloader = wait(deferred)
     return downloader
示例#6
0
 def _makeDataConnection(self, ignored=None):
     # Establish an active data connection (i.e. server connecting to
     # client).
     deferred = defer.Deferred()
     class DataFactory(protocol.ServerFactory):
         protocol = _BufferingProtocol
         def buildProtocol(self, addr):
             p = protocol.ServerFactory.buildProtocol(self, addr)
             reactor.callLater(0, deferred.callback, p)
             return p
     dataPort = reactor.listenTCP(0, DataFactory(), interface='127.0.0.1')
     self.dataPorts.append(dataPort)
     cmd = 'PORT ' + ftp.encodeHostPort('127.0.0.1', dataPort.getHost().port)
     self.client.queueStringCommand(cmd)
     return deferred
示例#7
0
    def testPORTCannotConnect(self):
        # Login
        self._anonymousLogin()

        # Listen on a port, and immediately stop listening as a way to find a
        # port number that is definitely closed.
        port = reactor.listenTCP(0, protocol.Factory(), interface="127.0.0.1")
        portNum = port.getHost().port
        d = port.stopListening()
        if d is not None:
            wait(d)

        # Tell the server to connect to that port with a PORT command, and
        # verify that it fails with the right error.
        cmd = "PORT " + ftp.encodeHostPort("127.0.0.1", portNum)
        d = self.client.queueStringCommand(cmd)
        self.failUnlessEqual(["425 Can't open data connection."], self._waitForCommandFailure(d))
示例#8
0
    def testPORTCannotConnect(self):
        # Login
        self._anonymousLogin()

        # Listen on a port, and immediately stop listening as a way to find a
        # port number that is definitely closed.
        port = reactor.listenTCP(0, protocol.Factory(), interface='127.0.0.1')
        portNum = port.getHost().port
        d = port.stopListening()
        if d is not None:
            wait(d)

        # Tell the server to connect to that port with a PORT command, and
        # verify that it fails with the right error.
        cmd = 'PORT ' + ftp.encodeHostPort('127.0.0.1', portNum)
        d = self.client.queueStringCommand(cmd)
        self.failUnlessEqual(["425 Can't open data connection."],
                             self._waitForCommandFailure(d))
示例#9
0
    def _makeDataConnection(self, ignored=None):
        # Establish an active data connection (i.e. server connecting to
        # client).
        deferred = defer.Deferred()

        class DataFactory(protocol.ServerFactory):
            protocol = _BufferingProtocol

            def buildProtocol(self, addr):
                p = protocol.ServerFactory.buildProtocol(self, addr)
                reactor.callLater(0, deferred.callback, p)
                return p

        dataPort = reactor.listenTCP(0, DataFactory(), interface='127.0.0.1')
        self.dataPorts.append(dataPort)
        cmd = 'PORT ' + ftp.encodeHostPort('127.0.0.1',
                                           dataPort.getHost().port)
        self.client.queueStringCommand(cmd)
        return deferred
示例#10
0
 def ftp_PASV(self):
     '''
     Overwrite ftp_PASV of ftp.FTP
     Original ftp_PASV implementation cannot support ftp_REST as it returns
     a defer, which blocks receiving next ftp_RETR command.
     Ref the description of ftp_REST command
     '''
     #raise None
     if self.dtpFactory is not None:
         self.cleanupDTP()
     self.dtpFactory = ftp.DTPFactory(pi=self)
     self.dtpFactory.setTimeout(self.dtpTimeout)
     #self.dtpPort = self.getDTPPort(self.dtpFactory)
     self.dtpPort = reactor.listenTCP(0, self.dtpFactory)
     #print "dtp port", self.dtpPort   
     host = self.transport.getHost().host
     port = self.dtpPort.getHost().port
     self.reply(ftp.ENTERING_PASV_MODE, ftp.encodeHostPort(host, port))
     #self.dtpFactory.deferred.addCallback(lambda ign: None)
     return 
示例#11
0
文件: txutil.py 项目: jamjr/crossbar
   def ftp_PASV(self):
      # if we have a DTP port set up, lose it.
      if self.dtpFactory is not None:
          # cleanupDTP sets dtpFactory to none.  Later we'll do
          # cleanup here or something.
          self.cleanupDTP()
      self.dtpFactory = DTPFactory(pi=self)
      self.dtpFactory.setTimeout(self.dtpTimeout)
      self.dtpPort = self.getDTPPort(self.dtpFactory)

      if self.factory.passivePublicIp is not None:
         # use explicit public IP for passive mode (when behind load-balancer or such)
         host = self.factory.passivePublicIp
         log.msg("using explicit public IP %s" % host)
      else:
         # use transport IP
         host = self.transport.getHost().host
         log.msg("using transport IP %s" % host)

      port = self.dtpPort.getHost().port
      self.reply(ENTERING_PASV_MODE, encodeHostPort(host, port))
      return self.dtpFactory.deferred.addCallback(lambda ign: None)
示例#12
0
 def gotPortNum(portNum):
     return self.assertCommandFailed(
         'PORT ' + ftp.encodeHostPort('127.0.0.1', portNum),
         ["425 Can't open data connection."])
示例#13
0
 def gotPortNum(portNum):
     return self.assertCommandFailed(
         'PORT ' + ftp.encodeHostPort('127.0.0.1', portNum),
         ["425 Can't open data connection."])