-
-
Notifications
You must be signed in to change notification settings - Fork 48.7k
added socket programming ftp algorithm #11602
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
Changes from all commits
6e62943
b2ed780
df5f14d
204a3fe
2aa2220
1846e55
5cf7a06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello world |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import socket | ||
|
||
|
||
def start_ftp_server(host, port) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: Please provide type hint for the parameter: |
||
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
server_socket.bind((host, port)) | ||
server_socket.listen(1) | ||
|
||
print(f"Server listening on {host}:{port}...") | ||
|
||
while True: | ||
client_socket, client_address = server_socket.accept() | ||
print(f"Connection from {client_address}") | ||
|
||
file_name = client_socket.recv(1024).decode() | ||
print(f"Receiving file: {file_name}") | ||
|
||
with open(file_name, "wb") as file: | ||
while True: | ||
data = client_socket.recv(1024) | ||
if not data: | ||
break | ||
file.write(data) | ||
|
||
print(f"File {file_name} received successfully.") | ||
client_socket.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
host = "127.0.0.1" | ||
port = 12345 | ||
|
||
start_ftp_server(host, port) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import socket | ||
|
||
|
||
def send_file_to_server(host, port, file_path) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: |
||
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
client_socket.connect((host, port)) | ||
|
||
file_name = file_path.split("/")[-1] | ||
client_socket.send(file_name.encode()) | ||
|
||
with open(file_path, "rb") as file: | ||
while True: | ||
data = file.read(1024) | ||
if not data: | ||
break | ||
client_socket.send(data) | ||
|
||
print(f"File {file_name} sent successfully.") | ||
client_socket.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
host = "127.0.0.1" | ||
port = 12345 | ||
|
||
file_path = "file.txt" | ||
|
||
send_file_to_server(host, port, file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file
socket_programming/file_transfer/receiver.py
, please provide doctest for the functionstart_ftp_server
Please provide type hint for the parameter:
host
Please provide type hint for the parameter:
port