i want to download a file from this url (http://justlearn.16mb.com/a.jpg) using python sockets only and i dont know how to do it as i am a novice in python.
Actually my main goal is to download files in half part using wifi connection and other half part using ethernet connection.
Thank you in advance for helping.
import os
import socket
tcpd = 'http://justlearn.16mb.com/a.jpg'
portd = 80
ipd = socket.gethostbyname('http://justlearn.16mb.com/a.jpg')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((tcpd,portd))
BUFFER_SIZE = 1024
with open('a.jpg', 'wb') as f:
print ('file opened')
while True:
#print('receiving data...')
data = s.recv(1024)
#print('data=%s', (data))
if not data:
f.close()
break
# write data to a file
f.write(data)
print('Successfully get the file')
s.close()
print('connection closed')