-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
aa55fab
added sample file to transfer
AlexDvorak b80a0d9
split client and server into separate files
AlexDvorak 72fc419
client and server now work in python2
AlexDvorak f664265
server works on python3
AlexDvorak 8c97bf4
client works on python3
AlexDvorak d1903ef
allow configurable ONE_CONNECTION_ONLY for testing server
AlexDvorak ce14986
allow testing of ftp server + client
AlexDvorak e717e4b
use f-strings
AlexDvorak 0fcaebd
Merge branch 'master' into fix_ftp
cclauss e9326b6
removed single letter vars
AlexDvorak 179288c
Merge branch 'fix_ftp' of https://github.com/AlexDvorak/Python into f…
AlexDvorak dda736f
fixed bad quote marks
AlexDvorak 3f8af01
clearer file handler names
AlexDvorak 317fffc
'with open() as' syntax
AlexDvorak db37b8f
unicode and emojis in the test data
AlexDvorak 06698bd
s -> sock
AlexDvorak d951521
consistent comment spacing
AlexDvorak ce9284f
remove closing formalities
AlexDvorak 6783c8a
swap in and out_file
AlexDvorak 4cad0ba
f-string
AlexDvorak 3d9639b
if __name__ == '__main__':
AlexDvorak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not data: | ||
break | ||
# write data to a file | ||
f.write(data) | ||
|
||
print('Successfully got the file') | ||
s.close() | ||
print('Connection closed') |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hello | ||
This is sample data | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
AlexDvorak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
conn.send(l) | ||
print('Sent ',repr(l)) | ||
l = f.read(1024) | ||
f.close() | ||
|
||
print('Done sending') | ||
conn.send(b'Thank you for connecting') | ||
AlexDvorak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.