Example #1
0
    def retr(self, path, request):
        '''Executes the FTP RETR command on the given path.'''
        data = BytesIO()

        # To ensure the BytesIO gets cleaned up, we need to alias its close
        # method. See self.list().
        data.release_conn = data.close

        code = self.conn.retrbinary('RETR ' + path, data_callback_factory(data))

        response = build_binary_response(request, data, code)

        # Close the connection.
        self.conn.close()

        return response
Example #2
0
    def retr(self, path, request):
        '''Executes the FTP RETR command on the given path.'''
        data = BytesIO()

        # To ensure the BytesIO gets cleaned up, we need to alias its close
        # method. See self.list().
        data.release_conn = data.close

        code = self.conn.retrbinary('RETR ' + path, data_callback_factory(data))

        response = build_binary_response(request, data, code)

        # Close the connection.
        self.conn.close()

        return response
Example #3
0
    def nlst(self, path, request):
        '''Executes the FTP NLST command on the given path.'''
        data = BytesIO()

        # Alias the close method.
        data.release_conn = data.close

        self.conn.cwd(path)
        code = self.conn.retrbinary('NLST', data_callback_factory(data))

        # When that call has finished executing, we'll have all our data.
        response = build_text_response(request, data, code)

        # Close the connection.
        self.conn.close()

        return response
Example #4
0
    def nlst(self, path, request):
        '''Executes the FTP NLST command on the given path.'''
        data = BytesIO()

        # Alias the close method.
        data.release_conn = data.close

        self.conn.cwd(path)
        code = self.conn.retrbinary('NLST', data_callback_factory(data))

        # When that call has finished executing, we'll have all our data.
        response = build_text_response(request, data, code)

        # Close the connection.
        self.conn.close()

        return response
Example #5
0
    def mlsd(self, path, request):
        '''Executes the FTP MLSD command on the given path.'''
        data = BytesIO()

        # To ensure the BytesIO gets cleaned up, we need to alias its close
        # method. See self.list().
        data.release_conn = data.close

        self.conn.cwd(path)
        code = self.conn.retrbinary('MLSD', data_callback_factory(data))

        # When that call has finished executing, we'll have all our data.
        response = build_text_response(request, data, code)

        # Close the connection.
        self.conn.close()

        return response
Example #6
0
    def mlsd(self, path, request):
        '''Executes the FTP MLSD command on the given path.'''
        data = BytesIO()

        # To ensure the BytesIO gets cleaned up, we need to alias its close
        # method. See self.list().
        data.release_conn = data.close

        self.conn.cwd(path)
        code = self.conn.retrbinary('MLSD', data_callback_factory(data))

        # When that call has finished executing, we'll have all our data.
        response = build_text_response(request, data, code)

        # Close the connection.
        self.conn.close()

        return response
Example #7
0
    def list(self, path, request):
        '''Executes the FTP LIST command on the given path.'''
        data = BytesIO()

        # To ensure the BytesIO object gets cleaned up, we need to alias its
        # close method to the release_conn() method. This is a dirty hack, but
        # there you go.
        data.release_conn = data.close

        self.conn.cwd(path)
        code = self.conn.retrbinary('LIST', data_callback_factory(data))

        # When that call has finished executing, we'll have all our data.
        response = build_text_response(request, data, code)

        # Close the connection.
        self.conn.close()

        return response
Example #8
0
    def list(self, path, request):
        '''Executes the FTP LIST command on the given path.'''
        data = BytesIO()

        # To ensure the BytesIO object gets cleaned up, we need to alias its
        # close method to the release_conn() method. This is a dirty hack, but
        # there you go.
        data.release_conn = data.close

        self.conn.cwd(path)
        code = self.conn.retrbinary('LIST', data_callback_factory(data))

        # When that call has finished executing, we'll have all our data.
        response = build_text_response(request, data, code)

        # Close the connection.
        self.conn.close()

        return response
Example #9
0
    def size(self, path, request):
        '''Executes the FTP SIZE command on the given path.'''
        self.conn.voidcmd('TYPE I')  # SIZE is not usually allowed in ASCII mode

        size = self.conn.size(path)

        if not str(size).isdigit():
            self.conn.close()
            return None

        data = BytesIO(bytes(size))
        # To ensure the BytesIO gets cleaned up, we need to alias its close
        # method to the release_conn() method. This is a dirty hack, but there
        # you go.
        data.release_conn = data.close
        data.content_len = size

        response = build_text_response(request, data, '213')

        self.conn.close()

        return response
Example #10
0
    def size(self, path, request):
        '''Executes the FTP SIZE command on the given path.'''
        self.conn.voidcmd(
            'TYPE I')  # SIZE is not usually allowed in ASCII mode

        size = self.conn.size(path)

        if not str(size).isdigit():
            self.conn.close()
            return None

        data = BytesIO(bytes(size))
        # To ensure the BytesIO gets cleaned up, we need to alias its close
        # method to the release_conn() method. This is a dirty hack, but there
        # you go.
        data.release_conn = data.close
        data.content_len = size

        response = build_text_response(request, data, '213')

        self.conn.close()

        return response