tarfile : read from a socket?
Ulli Horlacher
framstag at rus.uni-stuttgart.de
Thu Feb 11 07:53:09 EST 2016
Antoon Pardon <antoon.pardon at rece.vub.ac.be> wrote:
> > (How) can I read a tar file from a (tcp) socket?
> > I do not have a pathname but a socket object from socket.create_connection
>
> # First you construct a file object with makefile.
>
> fo = socket.makefile()
>
> # Then you use the fileobj argument with tarfile.open.
>
> tarfile.open(mode='r', fileobj = fo)
I have:
sock = socket.create_connection((server,port))
bs = kB64
taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
Traceback (most recent call last):
(...)
File "./fexit.py", line 1838, in sex_send
taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
File "/usr/lib/python2.7/tarfile.py", line 1695, in open
return cls.taropen(name, mode, fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
return cls(name, mode, fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
self.offset = self.fileobj.tell()
AttributeError: '_fileobject' object has no attribute 'tell'
--
Ullrich Horlacher Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart Tel: ++49-711-68565868
Allmandring 30a Fax: ++49-711-682357
70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/
More information about the Python-list
mailing list