Enviado em 26/04/2020 - 23:36h
boa noite a todos!
#!/usr/bin/env python
#-*-coding: utf-8-*-
#server
import socket
host = ""
port = 4422
adr = (host, port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(adr)
s.listen(1)
#lista diretorios
def lsd():
x = raw_input("DIR> ")
con.send(x)
msg = con.recv(1024)
print msg
#ler arquivos
def cat():
x = raw_input("FILE> ")
con.send(x)
msg = con.recv(1024)
#copia arquivos
def cp():
x = raw_input("COPY> ")
y = raw_input("NEW> ")
with open(y, "wb") as fl:
con.send(x)
msg = con.recv(4096)
fl.write(str(msg.read()))
print "Esperando conexão..."
con, dd = s.accept()
print "Conexão estabelecida com host ", dd
while True:
cmd = raw_input("CMD> ")
if cmd == "lsd":
lsd()
elif cmd == "cat":
cat()
elif cmd == "cp":
cp()
elif cmd == "bye":
con.send("bye")
exit()
else:
print "???"
s.close()
#!/usr/bin/env python
#-*-coding: utf-8-*-
import socket
import glob
#lista diretorios e arquivos
def lsd():
x = s.recv(1024)
_dir = glob.glob(x)
for out in _dir.readlines():
s.send(out)
#ler arquivos
def cat():
x = s.recv(1024)
with open(x, "rb") as fl:
s.send(fl.read())
#copia arquivos
def cp():
x = s.recv(1024)
with open(x, "rb") as fl:
s.send(str(fl.read()))
#tudo pronto, vamos prosseguir
h = ""
p = 4422
adr = (h, p)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(adr)
while True:
cmd = s.recv(1024)
if cmd == "lsd":
lsd()
elif cmd == "cat":
cat()
elif cmd == "cp":
cp()
else:
s.send("bye")
exit()
s.close()