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:
committed by
Christian Clauss
parent
561a41464f
commit
9456e81437
23
file_transfer_protocol/client.py
Normal file
23
file_transfer_protocol/client.py
Normal 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')
|
||||
Reference in New Issue
Block a user