Validate user on FreeBSD

Dan Nyanko cp_ru at chilitech.net
Wed Mar 19 11:25:01 EST 2003


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()




More information about the Python-list mailing list