Skip to content

Commit 0eae534

Browse files
authored
Add files via upload
1 parent 83baed6 commit 0eae534

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

docs/1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello!

docs/2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello from second file

ftp-client.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import socket
2+
3+
HOST = 'localhost'
4+
PORT = 6666
5+
6+
while True:
7+
request = input('>')
8+
9+
sock = socket.socket()
10+
sock.connect((HOST, PORT))
11+
12+
sock.send(request.encode())
13+
14+
response = sock.recv(1024).decode()
15+
print(response)
16+
17+
sock.close()

ftp-server.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import socket
2+
import os
3+
'''
4+
pwd - показывает название рабочей директории
5+
ls - показывает содержимое текущей директории
6+
cat <filename> - отправляет содержимое файла
7+
'''
8+
9+
dirname = os.path.join(os.getcwd(), 'docs')
10+
11+
def process(req):
12+
if req == 'pwd':
13+
return dirname
14+
elif req == 'ls':
15+
return '; '.join(os.listdir(dirname))
16+
return 'bad request'
17+
18+
19+
PORT = 6666
20+
21+
sock = socket.socket()
22+
sock.bind(('', PORT))
23+
sock.listen()
24+
print("Прослушиваем порт", PORT)
25+
26+
while True:
27+
conn, addr = sock.accept()
28+
29+
request = conn.recv(1024).decode()
30+
print(request)
31+
32+
response = process(request)
33+
conn.send(response.encode())
34+
35+
conn.close()

0 commit comments

Comments
 (0)