Sending directory with files in it via sockets

R

Ryniek90

Hi.
Last time i've got problem with sending big files, but i've already
dealt with it.
Now, when i want send directory (with some files in it) i iterate that
directory for files in it, and then in while loop open iterated files,
read them and send. But something's not working. It iterate's first file
from directory and sends it all the time (only first file). So, the
iteration is written bad. Could you tell me how to modify it?

Here's that method:

def send_dir(self):
print "Gathering information's..."
self.direc = os.walk(self.data)
for files in self.direc:
lst_files = files[2]
for fl in lst_files:
print "Sending %s from directory %s" % (fl,
os.path.split(self.data)[1])
while True:
files = open("%s/%s" % (self.data,fl), 'rb')
self.read = files.read(51200)
self.konn.send(self.read)
if not self.read:
break
files.close()

"self.data" is variable for the "self.konn.recv(4096") method.
self.konn is from "self.konn, self.addr = self.sok.accept()"

"self.direc = os.walk(self.data)
for files in self.direc:
lst_files = files[2]"

Iteration result looks like this:
lst_files = files[2]

>>> lst_files ['hl2_1.nrg', 'hl2_2.nrg', 'hl2_4.nrg', 'hl2_5.nrg']
>>> for fl in lst_files:
print fl


hl2_1.nrg
hl2_2.nrg
hl2_4.nrg
hl2_5.nrg
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top