Sending directory with files in it via sockets

Ryniek90 ryniek90 at gmail.com
Fri Apr 17 23:24:35 CEST 2009


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:

 >>> import os
 >>> direc = os.walk('/media/DOWNLOAD/Obrazy płyt/Half-Life 2')
 >>> for files in direc:
    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.



More information about the Python-list mailing list