Skip to content

Seperate client and server of FTP #1106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ script:
- pytest . --doctest-modules
--ignore=data_structures/stacks/balanced_parentheses.py
--ignore=data_structures/stacks/infix_to_postfix_conversion.py
--ignore=file_transfer_protocol/ftp_send_receive.py
--ignore=file_transfer_protocol/ftp_client_server.py
--ignore=machine_learning/linear_regression.py
--ignore=machine_learning/perceptron.py
--ignore=machine_learning/random_forest_classification/random_forest_classification.py
Expand Down
23 changes: 23 additions & 0 deletions file_transfer_protocol/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import socket # Import socket module

s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12312

s.connect((host, port))
s.send(b'Hello server!')

with open('Received_file', 'wb') as f:
print('File opened')
print('Receiving data...')
while True:
data = s.recv(1024)
print('data='+str(data))
if not data:
break
# write data to a file
f.write(data)

print('Successfully got the file')
s.close()
print('Connection closed')
57 changes: 0 additions & 57 deletions file_transfer_protocol/ftp_client_server.py

This file was deleted.

2 changes: 2 additions & 0 deletions file_transfer_protocol/mytext.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello
This is sample data
34 changes: 34 additions & 0 deletions file_transfer_protocol/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import socket # Import socket module

ONE_CONNECTION_ONLY = True # Set this to False if you wish to continuously accept connections

port = 12312 # Reserve a port for your service.
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.

print('Server listening....')

while True:
conn, addr = s.accept() # Establish connection with client.
print('Got connection from', addr)
data = conn.recv(1024)
print('Server received', repr(data))

filename='mytext.txt'
f = open(filename,'rb')
l = f.read(1024)
while (l):
conn.send(l)
print('Sent ',repr(l))
l = f.read(1024)
f.close()

print('Done sending')
conn.send(b'Thank you for connecting')
conn.close()
if ONE_CONNECTION_ONLY: # This is to make sure that the program doesn't hang while testing
break
s.shutdown(1)
s.close()