PYTHON-TCP Analog FTP File transfer

Source: Internet
Author: User
Tags ftp file ftp file transfer

1  #!/usr/bin/python2 #Coding=utf-83 #Server4  fromSocketImport*5 ImportSys,os6 defcommand ():7l=["welcome!\n","command\n","list\n","upload\n","download\n"]8     returnL9 deflist ():TenL=[] One      forFileNameinchOs.listdir ('.'): A l.append (filename) -     returnL -host="192.168.1.33" theport=5126 -Addr=(Host,port) -sockob=socket (af_inet,sock_stream) - Sockob.bind (ADDR) +Sockob.listen (5) -  +A=[] A  while1: atSock,addr=sockob.accept () -  -      while1: -DATA=SOCK.RECV (1024)  -Str=data.split (" ") -  in         ifdata = ="Command": -A=command () to              forIinchA: + sock.send (i) -         elifdata = ="List": theA=list () *              forIinchA: $ sock.send (i)Panax Notoginseng         elifstr[0]=="Upload": -F=open (Str[1],'W') theS=SOCK.RECV (1024) +             Prints A              forIinchS#Range (len (str)): the F.write (i) +             Print "upload is ok!" -         elifstr[0]=="Download": $F=open (Str[1],'R') $s=F.readlines () -              forIinchS: - sock.send (i) the             Print "download is ok!" - sockob.close ()WuyiSock.close ()
1 #!/usr/bin/python2 #Coding=utf-83 #Client4  fromSocketImport*5 ImportSYS6 7host='192.168.1.33'8port=51269Addr=(Host,port)Tensockob=socket (af_inet,sock_stream) One Sockob.connect (ADDR) A  -  while1: -Data=raw_input (">",) theStr=data.split (' ') -     if  notStr: -          Break -     elifstr[0]=="Upload": +F=open (Str[1],'R') - sockob.send (data) +s0=F.readlines () A         PrintS0 at          forIinchs0: - sockob.send (i) -     elifstr[0]=="Download": -F=open (Str[1],'W') - sockob.send (data) -S1=SOCKOB.RECV (1024) in f.write (S1) -     elifdata=="Command" ordata=="List": to sockob.send (data) +DATA=SOCKOB.RECV (1024) -         PrintData the  *  $Sockob.close ()

PYTHON-TCP Analog FTP File transfer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.