send remote name with dirbytes dropdir os path split(filename)[ filename at end of dir path file open(dropdir'wb'create local file in cwd while truedata sock recv(blkszget up to at time if not databreak till closed on server side file write(datastore data in local file sock close(file close(print('client got'filename'at'now()def serverthread(clientsock)sockfile clientsock makefile(' 'wrap socket in dup file obj filename sockfile readline()[:- get filename up to end-line tryfile open(filename'rb'while truebytes file read(blkszread/send at time if not bytesbreak until file totally sent sent clientsock send(bytesassert sent =len(bytesexceptprint('error downloading file on server:'filenameclientsock close(def server(hostport)serversock socket(af_inetsock_streamlisten on tcp/ip socket serversock bind((hostport)serve clients in threads serversock listen( while trueclientsockclientaddr serversock accept(print('server connected by'clientaddr'at'now()thread start_new_thread(serverthread(clientsock,)def main(args)host args get('-host'defaulthostport int(args get('-port'defaultport)if args get('-mode'='server'if host ='localhost'host 'server(hostportelif args get('-file')client(hostportargs['-file']elseprint(helptextuse args or defaults is string in argv none if no -modeclient else fails remotely client mode needs -file if __name__ ='__main__'args parsecommandline(main(argsthis script isn' much different from the examples we saw earlier depending on the command-line arguments passedit invokes one of two functionsthe server function farms out each incoming client request to thread that transfers the requested file' bytes simple python file server