Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Sending directory with files in it via sockets

Reply
Thread Tools

Sending directory with files in it via sockets

 
 
Ryniek90
Guest
Posts: n/a
 
      04-17-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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending HTTP headers via plain sockets Navkirat Singh Python 0 07-23-2010 01:30 AM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
Sending pictures via email Via OE6+Win XP - I no longer get prompt to "make all my pictures smaller" Ian Roberts Digital Photography 3 09-21-2003 04:57 PM
Re: sending objects over sockets Steve Horsley Java 0 06-27-2003 01:51 PM
Re: sending objects over sockets Steve Horsley Java 0 06-27-2003 01:51 PM



Advertisments