Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the usage of IOStrings and do not close file objects #7

Open
robertpenz opened this issue Feb 23, 2015 · 0 comments
Open

Allow the usage of IOStrings and do not close file objects #7

robertpenz opened this issue Feb 23, 2015 · 0 comments

Comments

@robertpenz
Copy link

It would be nice that the tftpclient could be used to download a file into memory (IOStrings). I did a quick and dirty method for TFTPClient:

    def getAsIOString(self, filepath):
        """ zieht das file in einen String """
        self.PTFTP_STATE = state.TFTPState(self.peer, proto.OP_RRQ,
                '', filepath, self.transfer_mode, not self.rfc1350)

        self.PTFTP_STATE.file = StringIO.StringIO()
        self.PTFTP_STATE.packetnum = 1
        self.PTFTP_STATE.state = state.STATE_RECV

        opts = dict(self.opts)

        # When not running in RFC1350 compliance mode, append tsize: 0
        # to the list of options in the request to get the requested
        # file size back in the OACK.
        if not self.rfc1350:
            opts[proto.TFTP_OPTION_TSIZE] = 0

        packet = proto.TFTPHelper.createRRQ(filepath, self.transfer_mode, opts)

        self.sock.sendto(packet, self.peer)
        self.handle()

        if self.error:
            error, errmsg = self.error
            raise IOError('Downloading failed (%r, %r)' % (error, errmsg))
        return self.PTFTP_STATE.file

But that only works if I remove the close() functions in state.py. But as I'm not that deep into that code I don't know what that breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant