我在客户端的代码中有这个,它向服务器发送请求以发送文件。
客户端:
filetoopen = tokens[1]
msg = "RETR " + filetoopen
sock.send( msg.encode() )
file2 = open( filetoopen , "w")`
while True:
file = sock.recv(1024).decode()
if(not file or file == '' or len(file) <= 0 ):
file2.close()
break
else:
file2.write(file)
print(file)
print("FILE : " , file)
print("\n File [ " + filetoopen + " ] has been transfered to the current working directory")
print("from the remote server.\n")
SERVER:
openfile = open(file , "r")
file = openfile.read()
while (file != ''):
sock.send(file.encode())
file = openfile.read()
openfile.close()
print("CLOSED FILE")
(&#39; file&#39;是作为参数发送的文件名)