Isn't it tedious to always reach out for a USB cable and then connect phone with computer, wait while computer detects, then browse for files and then finally transfer! What a pain to do so many steps.
Worry not, here is a wireless solution to copy data from one device to other. All you need is Python and a supporting mobile app!
To do this, we will be using a simple concept: HTTP Server and Client. A server will be source of files and a client will be the one copying files from server.
Since we will be transferring files wireless, we need to connect mobile and computer to a common WiFi router. If you don't have a router, turn hotspot on from your mobile and connect your computer to it.
Transfer files from computer to phone
- Make sure you have python installed. If not then first install python.
- Next step is to check version of python. Open a terminal (or command prompt on Windows) and run
python --version
- If you have a python version starting from
3.x
, then run the commandpython -m http.server
in terminal. - If your python version is
2.x
then runpython -m SimpleHTTPServer
-
Next get the private IP address of your machine.
- For Windows, open command prompt and run
ipconfig
. Your local IP address will be listed under ‘IPv4 Address’. - For Linux and Mac, open terminal and run command
ifconfig
. In the resulting information spewed out, we are looking for the section starting withwl
. It could bewlp3s0
or something else. Basically it denotes wireless lan. Under this section, we need address afterinet
. In my case, it's192.168.10.11
.
- For Windows, open command prompt and run
Once we have the IP address, go to the browser in your phone and enter that address with a
:8000
at the end in address bar. This8000
comes from the output ofpython -m http.server
command. As you can see in above image, default port is8000
. For my case, I would enter192.168.10.11:8000
in my mobile browser and go to the link. Once the page loads, congrats, you may navigate to the file and download it.If page doesn't load in mobile browser, make sure that you do not have a
https://
at start of URL. If present then remove it.
Bonus: If you need a specific file, then in terminal navigate to the directory where file is present and run the python server command in that directory. Python server will start from which ever directory command is executed.
Transfer files from phone to computer
- For this you will need a mobile app to run HTTP Server like this or any other app. Just open the app and run the server. For this app, click on "off" to turn the server on.
- Open the link given on computer browser. From above screenshot,
192.168.10.2:12345/
. And done! Browser files present in your phone from your computer.
- Open the link given on computer browser. From above screenshot,
Top comments (4)
Hey Chinmay,
I turned this idea into a small program. It gets the IP address automatically. Run it like this
$ python3 server_files.py
OR like this
$ python3 server_files.py --host '192.168.12.34' --port 1234
github.com/brandon-wallace/serve_f...
Wait, so is that actually possible?! It sounds like something incredible! I think this kind of small program should be in demand as a hell of a lot of people are likely to transfer some files from computer to their phone or vice versa without those stupid cables, but sometimes it might happen that you might not have internet, and here comes this program. Well, I would be using this program at least once per day, as my cox wifi is terrible. I have to keep this guide xtrium.com/cox-panoramic-wifi-not-... as wallpaper on my pc, so I know how to repair the damn router.
It looks great, I will try it when I have time
Noice! I like this idea.