Upload 13 files
Browse files- app.py.py +83 -0
- hive.txt +1 -0
- img.jpg +0 -0
- img2.jpg +0 -0
- readme.md +9 -0
- recer +0 -0
- sample_image.png +0 -0
- sample_pdf.pdf +0 -0
- sample_python.py +1 -0
- sample_text.txt +1 -0
- sender.py +51 -0
- sender_streamlit.py +59 -0
- sender_without.py +42 -0
app.py.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file will be used for recieving files over socket connection.
|
2 |
+
import os
|
3 |
+
import socket
|
4 |
+
import time
|
5 |
+
import streamlit as st
|
6 |
+
# import streamlit as st
|
7 |
+
# import time
|
8 |
+
|
9 |
+
progress_text = "File Transferring...Please Wait"
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
from PIL import Image
|
14 |
+
|
15 |
+
image = Image.open('img2.jpg')
|
16 |
+
|
17 |
+
st.image(image)
|
18 |
+
|
19 |
+
st.title('Reciver Page')
|
20 |
+
st.divider()
|
21 |
+
st.header("Share files easily, securely, and fast!")
|
22 |
+
host = st.text_input("Host Name: ")
|
23 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
24 |
+
|
25 |
+
# Trying to connect to socket.
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
with st.spinner('Searching For Sender...'):
|
30 |
+
time.sleep(3)
|
31 |
+
try:
|
32 |
+
sock.connect((host, 40000))
|
33 |
+
st.warning("Connected Successfully...",icon="✔")
|
34 |
+
except:
|
35 |
+
st.warning("Unable to connect",icon="⚠️")
|
36 |
+
exit(0)
|
37 |
+
|
38 |
+
# Send file details.
|
39 |
+
file_name = sock.recv(100).decode()
|
40 |
+
|
41 |
+
file_size = sock.recv(100).decode()
|
42 |
+
|
43 |
+
# Opening and reading file.
|
44 |
+
with open("./rec/" + file_name, "wb") as file:
|
45 |
+
c = 0
|
46 |
+
my_bar = st.progress(0, text=progress_text)
|
47 |
+
st.write("Waiting for Sender to select the File")
|
48 |
+
# Starting the time capture.
|
49 |
+
start_time = time.time()
|
50 |
+
|
51 |
+
# Running the loop while file is recieved.
|
52 |
+
while c <= int(file_size):
|
53 |
+
# my_bar.progress(50, text=progress_text)
|
54 |
+
|
55 |
+
data = sock.recv(1024)
|
56 |
+
if not (data):
|
57 |
+
break
|
58 |
+
file.write(data)
|
59 |
+
|
60 |
+
c += len(data)
|
61 |
+
|
62 |
+
|
63 |
+
# Ending the time capture.
|
64 |
+
end_time = time.time()
|
65 |
+
for percent_complete in range(100):
|
66 |
+
time.sleep(0.1)
|
67 |
+
my_bar.progress(percent_complete + 1, text=progress_text)
|
68 |
+
# my_bar.progress(100, text=progress_text)
|
69 |
+
with open("./rec/" + file_name,"rb") as file:
|
70 |
+
btn = st.download_button(
|
71 |
+
label="Download File",
|
72 |
+
data=file,
|
73 |
+
file_name=file_name,
|
74 |
+
|
75 |
+
)
|
76 |
+
st.write("File transfer Complete.Total time: ", int(end_time - start_time))
|
77 |
+
|
78 |
+
# Closing the socket.
|
79 |
+
sock.close()
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
|
hive.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
hgsdyivgsduvbkshdn khjnunkj
|
img.jpg
ADDED
img2.jpg
ADDED
readme.md
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Transfer Files using Socket Programming! (Python)
|
2 |
+
|
3 |
+
Here is an Easy tutorial for socket programming in python to help you transfer files over internet.<br>
|
4 |
+
Can Transfer Videos, Images, PDFs and many more.<br><br>
|
5 |
+
Please subscribe to my channel and do hit the like button.
|
6 |
+
<br>
|
7 |
+
Link to this video: https://www.youtube.com/watch?v=SZyd7xGTBkw&t=115s
|
8 |
+
<br>
|
9 |
+
Link to my channel: https://www.youtube.com/channel/UCTew04It3cp3zVi9S0RBu9g
|
recer
ADDED
File without changes
|
sample_image.png
ADDED
sample_pdf.pdf
ADDED
Binary file (61.3 kB). View file
|
|
sample_python.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
print("This is the sample file")
|
sample_text.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
This is the sample Text file
|
sender.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file is used for sending the file over socket
|
2 |
+
import os
|
3 |
+
import socket
|
4 |
+
import time
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
# Creating a socket.
|
8 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
9 |
+
sock.bind((socket.gethostname(), 40000))
|
10 |
+
sock.listen(5)
|
11 |
+
print("Host Name: ", sock.getsockname())
|
12 |
+
# st.write( ,sock.getsockname())
|
13 |
+
|
14 |
+
|
15 |
+
st.write("Host Name and Port Number", sock.getsockname())
|
16 |
+
# Accepting the connection.
|
17 |
+
|
18 |
+
with st.spinner('Searching For Receiver...'):
|
19 |
+
client, addr = sock.accept()
|
20 |
+
# Getting file details.
|
21 |
+
# file_name = input("File Name:")
|
22 |
+
file_name = st.text_input("Enter your file Path👇 ",)
|
23 |
+
st.write(file_name)
|
24 |
+
if file_name:
|
25 |
+
|
26 |
+
file_size = os.path.getsize(file_name)
|
27 |
+
|
28 |
+
# Sending file_name and detail.
|
29 |
+
client.send(file_name.encode())
|
30 |
+
client.send(str(file_size).encode())
|
31 |
+
|
32 |
+
# Opening file and sending data.
|
33 |
+
with open(file_name, "rb") as file:
|
34 |
+
c = 0
|
35 |
+
# Starting the time capture.
|
36 |
+
start_time = time.time()
|
37 |
+
|
38 |
+
# Running loop while c != file_size.
|
39 |
+
while c <= file_size:
|
40 |
+
data = file.read(1024)
|
41 |
+
if not (data):
|
42 |
+
break
|
43 |
+
client.sendall(data)
|
44 |
+
c += len(data)
|
45 |
+
|
46 |
+
# Ending the time capture.
|
47 |
+
end_time = time.time()
|
48 |
+
|
49 |
+
st.write("File Transfer Complete.Total time: ", end_time - start_time)
|
50 |
+
sock.close()
|
51 |
+
|
sender_streamlit.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file is used for sending the file over socket
|
2 |
+
import os
|
3 |
+
import socket
|
4 |
+
import time
|
5 |
+
import streamlit as st
|
6 |
+
from PIL import Image
|
7 |
+
|
8 |
+
image = Image.open('img.jpg')
|
9 |
+
|
10 |
+
st.image(image)
|
11 |
+
|
12 |
+
st.title('Sender Page')
|
13 |
+
st.divider()
|
14 |
+
st.header("Share files easily, securely, and fast!")
|
15 |
+
|
16 |
+
# Creating a socket.
|
17 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
18 |
+
sock.bind((socket.gethostname(), 40000))
|
19 |
+
sock.listen(5)
|
20 |
+
st.write("Host Name: ", sock.getsockname())
|
21 |
+
st.divider()
|
22 |
+
with st.spinner('Searching For Receiver...'):
|
23 |
+
client, addr = sock.accept()
|
24 |
+
# Accepting the connection.
|
25 |
+
|
26 |
+
|
27 |
+
# Getting file details.
|
28 |
+
# file_name = st.text_input("File Name: ","sample_image.png")
|
29 |
+
file_name = st.selectbox(
|
30 |
+
'Select the File',
|
31 |
+
('sample_python.py', 'sample_image.png', 'sample_pdf.pdf',"sample_text.txt"))
|
32 |
+
st.write("File Selected: ", file_name)
|
33 |
+
if file_name != "":
|
34 |
+
file_size = os.path.getsize(file_name)
|
35 |
+
|
36 |
+
# Sending file_name and detail.
|
37 |
+
client.send(file_name.encode())
|
38 |
+
client.send(str(file_size).encode())
|
39 |
+
|
40 |
+
# Opening file and sending data.
|
41 |
+
with open(file_name, "rb") as file:
|
42 |
+
c = 0
|
43 |
+
# Starting the time capture.
|
44 |
+
start_time = time.time()
|
45 |
+
|
46 |
+
# Running loop while c != file_size.
|
47 |
+
while c <= file_size:
|
48 |
+
data = file.read(1024)
|
49 |
+
if not (data):
|
50 |
+
break
|
51 |
+
client.sendall(data)
|
52 |
+
c += len(data)
|
53 |
+
|
54 |
+
# Ending the time capture.
|
55 |
+
end_time = time.time()
|
56 |
+
|
57 |
+
st.write("File Transfer Complete.Total time: ", int(end_time - start_time))
|
58 |
+
# Cloasing the socket.
|
59 |
+
sock.close()
|
sender_without.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file is used for sending the file over socket
|
2 |
+
import os
|
3 |
+
import socket
|
4 |
+
import time
|
5 |
+
|
6 |
+
# Creating a socket.
|
7 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
8 |
+
sock.bind((socket.gethostname(), 40000))
|
9 |
+
sock.listen(5)
|
10 |
+
print("Host Name: ", sock.getsockname())
|
11 |
+
|
12 |
+
# Accepting the connection.
|
13 |
+
client, addr = sock.accept()
|
14 |
+
|
15 |
+
# Getting file details.
|
16 |
+
file_name = input("File Name:")
|
17 |
+
file_size = os.path.getsize(file_name)
|
18 |
+
|
19 |
+
# Sending file_name and detail.
|
20 |
+
client.send(file_name.encode())
|
21 |
+
client.send(str(file_size).encode())
|
22 |
+
|
23 |
+
# Opening file and sending data.
|
24 |
+
with open(file_name, "rb") as file:
|
25 |
+
c = 0
|
26 |
+
# Starting the time capture.
|
27 |
+
start_time = time.time()
|
28 |
+
|
29 |
+
# Running loop while c != file_size.
|
30 |
+
while c <= file_size:
|
31 |
+
data = file.read(1024)
|
32 |
+
if not (data):
|
33 |
+
break
|
34 |
+
client.sendall(data)
|
35 |
+
c += len(data)
|
36 |
+
|
37 |
+
# Ending the time capture.
|
38 |
+
end_time = time.time()
|
39 |
+
|
40 |
+
print("File Transfer Complete.Total time: ", end_time - start_time)
|
41 |
+
# Cloasing the socket.
|
42 |
+
sock.close()
|