ptftpd
ptftpd copied to clipboard
Allow the usage of IOStrings and do not close file objects
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.