Sending directory with files in it via sockets

Discussion in 'Python' started by Ryniek90, Apr 17, 2009.

  1. Ryniek90

    Ryniek90 Guest

    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.
     
    Ryniek90, Apr 17, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Horsley

    Re: sending objects over sockets

    Steve Horsley, Jun 27, 2003, in forum: Java
    Replies:
    0
    Views:
    1,156
    Steve Horsley
    Jun 27, 2003
  2. Steve Horsley

    Re: sending objects over sockets

    Steve Horsley, Jun 27, 2003, in forum: Java
    Replies:
    0
    Views:
    1,422
    Steve Horsley
    Jun 27, 2003
  3. Nazgul_zulus

    sending files via HTTP

    Nazgul_zulus, Jun 24, 2004, in forum: C++
    Replies:
    1
    Views:
    422
    Thomas Matthews
    Jun 24, 2004
  4. Navkirat Singh

    Sending HTTP headers via plain sockets

    Navkirat Singh, Jul 23, 2010, in forum: Python
    Replies:
    0
    Views:
    264
    Navkirat Singh
    Jul 23, 2010
  5. Manoj K.S
    Replies:
    2
    Views:
    431
    William Herrera
    Dec 3, 2003
Loading...

Share This Page