Python/file_transfer_protocol/client.py
AlexDvorak 9456e81437 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__':
2019-08-07 15:44:48 +02:00

24 lines
658 B
Python

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')