ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Validate user on FreeBSD
by Dan Nyanko other posts by this author
Mar 19 2003 4:25PM messages near this date
Re: Tutorial on programming devices? | Re: Validate user on FreeBSD
What I have working so far is the client can send a file across the
link to the server, and it is written into the directory that the
server program resides in.  I would like to add an authentication step
that would send it to the valid users home directory, e.g.
/home/cp_ru/filename.tar.gz

#--------------------------------------------------------------
from socket import *
from struct import *

serverAddress = "0.0.0.0"
header = "!I"
headerSize = calcsize(header)


def sockListen(): 
    sock = socket(AF_INET, SOCK_STREAM)
    sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)

    sock.bind((serverAddress, 510))
    sock.listen(5)
        
    conn, remoteAddress = sock.accept()
    print "Connected", remoteAddress

    return conn, remoteAddress

def closeConn(conn, remoteAddress):
    conn.close()
    print "Connection Terminated", remoteAddress

def main():     

    conn, remoteAddress = sockListen()

    filename = conn.recv(1024)

    fileSize = conn.recv(headerSize)
    fileSize = unpack(header, fileSize)
    fileSize = fileSize[0]
    f = open(filename, "wb")

    if fileSize != 0:
        print "\nTransferring "+filename
        while fileSize >  0:
            data = conn.recv(4096)
            if not data:
                f.close()
                break
            f.write(data)
            fileSize -= len(data)
        print "Transfer completed\n"

    if conn:
        closeConn(conn, remoteAddress)

if __name__ == "__main__":
    while 1:
        main()
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Dan Nyanko
Dan Nyanko
Steven Taschuk
Steven Taschuk

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved