Seperate client and server of FTP (#1106)

* added sample file to transfer

* split client and server into separate files

* client and server now work in python2

* server works on python3

* client works on python3

* allow configurable ONE_CONNECTION_ONLY for testing server

* allow testing of ftp server + client

* use f-strings

* removed single letter vars

* fixed bad quote marks

* clearer file handler names

* 'with open() as' syntax

* unicode and emojis in the test data

* s -> sock

* consistent comment spacing

* remove closing formalities

* swap in and out_file

* f-string

* if __name__ == '__main__':
This commit is contained in:
AlexDvorak
2019-08-07 09:44:48 -04:00
committed by Christian Clauss
parent 561a41464f
commit 9456e81437
5 changed files with 63 additions and 58 deletions

View File

@@ -0,0 +1,23 @@
if __name__ == '__main__':
import socket # Import socket module
sock = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12312
sock.connect((host, port))
sock.send(b'Hello server!')
with open('Received_file', 'wb') as out_file:
print('File opened')
print('Receiving data...')
while True:
data = sock.recv(1024)
print(f"data={data}")
if not data:
break
out_file.write(data) # Write data to a file
print('Successfully got the file')
sock.close()
print('Connection closed')