-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathftp_serv.py
47 lines (44 loc) · 847 Bytes
/
ftp_serv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os,socket
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('127.0.0.1',6660))
s.listen(5)
client,address=s.accept()
while True:
k=client.recv(1024)
if k=='get':
name=client.recv(1024)
os.system('cat '+name+'>out.txt')
file=open('out.txt','r')
out=' '
for l in file:
out+=l
client.send(out)
file.close()
if k=='put':
name=client.recv(1024)
file=open(name,"w")
file.write(client.recv(8192))
file.close()
if k=='pwd':
os.system("pwd>out.txt")
file=open('out.txt','r')
out=' '
for l in file:
out+=l
client.send(out)
file.close()
if k=='ls':
os.system("ls>out.txt")
file=open('out.txt','r')
out=' '
for l in file:
out+=l
client.send(out)
file.close()
if k=='cd':
path=client.recv(1024)
os.chdir(path)
if k=='quit':
s.close();
print 'exiting server mode'
break