(cls, output_file, adr, ftkey,
                 seekpos=0, total_size=0, reporthook=None)
return read_size
Downloads a file from a TS3 server in the file **output_file**. The
        TS3 file transfer interface is specified with the address tuple **adr**
        and the download with the file transfer key **ftkey**.

        If **seekpos** and the total **size** are provided, the **reporthook**
        function (lambda read_size, block_size, total_size: None) is called
        after receiving a new block.

        If you provide **seekpos** and **total_size**, this method will check,
        if the download is complete and raise a :exc:`TS3DownloadError` if not.

        Note, that if **total_size** is 0 or less, each download will be
        considered as complete.

        If no error is raised, the number of read bytes is returned.

        :return:
            The number of received bytes.
        :rtype:
            int

        :raises TS3DownloadError:
            If the download is incomplete or a socket error occured.
Downloads a file from a TS3 server in the file **output_file**. The
        TS3 file transfer interface is specified with the address tuple **adr**
        and the download with the file transfer key **ftkey**.
Downloads a file from a TS3 server in the file ** output_file ** . The TS3 file transfer interface is specified with the address tuple ** adr ** and the download with the file transfer key ** ftkey ** .
def download(cls, output_file, adr, ftkey,
                 seekpos=0, total_size=0, reporthook=None):
        """
        Downloads a file from a TS3 server in the file **output_file**. The
        TS3 file transfer interface is specified with the address tuple **adr**
        and the download with the file transfer key **ftkey**.

        If **seekpos** and the total **size** are provided, the **reporthook**
        function (lambda read_size, block_size, total_size: None) is called
        after receiving a new block.

        If you provide **seekpos** and **total_size**, this method will check,
        if the download is complete and raise a :exc:`TS3DownloadError` if not.

        Note, that if **total_size** is 0 or less, each download will be
        considered as complete.

        If no error is raised, the number of read bytes is returned.

        :return:
            The number of received bytes.
        :rtype:
            int

        :raises TS3DownloadError:
            If the download is incomplete or a socket error occured.
        """
        # Convert the ftkey if necessairy
        if isinstance(ftkey, str):
            ftkey = ftkey.encode()
        if seekpos < 0:
            raise ValueError("Seekpos has to be >= 0!")

        read_size = seekpos
        block_size = 4096
        try:
            with socket.create_connection(adr) as sock:
                sock.sendall(ftkey)

                # Begin with the download.
                if reporthook is not None:
                    reporthook(read_size, block_size, total_size)

                while True:
                    data = sock.recv(block_size)
                    output_file.write(data)

                    read_size += len(data)
                    if reporthook is not None:
                        reporthook(read_size, block_size, total_size)

                    # Break, if the connection has been closed.
                    if not data:
                        break

        # Catch all socket errors.
        except OSError as err:
            raise TS3DownloadError(read_size, err)

        # Raise an error, if the download is not complete.
        if read_size < total_size:
            raise TS3DownloadError(read_size)
        return read_size
def download ( cls , output_file , adr , ftkey , seekpos = 0 , total_size = 0 , reporthook = None ) : # Convert the ftkey if necessairy if isinstance ( ftkey , str ) : ftkey = ftkey . encode ( ) if seekpos < 0 : raise ValueError ( "Seekpos has to be >= 0!" ) read_size = seekpos block_size = 4096 try : with socket . create_connection ( adr ) as sock : sock . sendall ( ftkey ) # Begin with the download. if reporthook is not None : reporthook ( read_size , block_size , total_size ) while True : data = sock . recv ( block_size ) output_file . write ( data ) read_size += len ( data ) if reporthook is not None : reporthook ( read_size , block_size , total_size ) # Break, if the connection has been closed. if not data : break # Catch all socket errors. except OSError as err : raise TS3DownloadError ( read_size , err ) # Raise an error, if the download is not complete. if read_size < total_size : raise TS3DownloadError ( read_size ) return read_size