Guest User

Untitled

a guest
Sep 24th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #!/usr/bin/python
  2. from socket import *
  3.  
  4. host = "0.0.0.0"
  5. port = 21
  6.  
  7. s = socket(AF_INET, SOCK_STREAM)
  8. s.bind((host, port))
  9. s.listen(1)
  10.  
  11. cl, addr = s.accept()
  12. print "Connection accepted from %s" % addr[0]
  13.  
  14. def ftpserv():
  15. dirlist = "drwxrwxrwx 1 100 0 11111 Jun 11 21:10 file1.txt\r\n"
  16. dirlist += "-rw-rw-r-- 1 1176 1176 1060 Aug 22 22:22 file2.txt\r\n"
  17. welcome = "220 Welcome to Simple FTP Server\r\n"
  18. cl.send(welcome)
  19. cl.recv(1024)
  20. cl.send("331 User name okay, need password\r\n") # received USER
  21. cl.recv(1024)
  22. cl.send("230-Password accepted\r\n") # received PASS
  23. cl.send("230 User logged in.\r\n")
  24. cl.recv(1024)
  25. cl.send("215 UNIX Type: L8\r\n") # received from SYST
  26. cl.recv(1024)
  27. cl.send("211-Features:\r\n") # received from FEAT
  28. cl.send("211 End\r\n")
  29. cl.recv(1024)
  30. cl.send("200 Type set to I\r\n") # received from TYPE I
  31. cl.recv(1024)
  32. cl.send("200 OK\r\n") # received from REST 0
  33. cl.recv(1024)
  34. cl.send("257 \"/\" is current directory\r\n") # received from PWD
  35. cl.recv(1024)
  36. cl.send("227 Entering Passive Mode ("+addr[0]+",2521)\r\n")
  37. cl.recv(1024)
  38. cl.send("150 Here comes the directory listing\r\n") # received from LIST
  39. cl.send("total 2\r\n"+dirlist)
  40. cl.send("226 Directory send ok\r\n")
  41. cl.close()
  42. s.close()
Add Comment
Please, Sign In to add comment