Transfer files between your phone and computer without any cable and internet!

chinmay chhajed - Feb 22 '21 - - Dev Community

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 command python -m http.server in terminal.
  • If your python version is 2.x then run python -m SimpleHTTPServer

Output should look something like this in both the cases:
alt text

  • 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 with wl. It could be wlp3s0 or something else. Basically it denotes wireless lan. Under this section, we need address after inet. In my case, it's 192.168.10.11. alt text
  • 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. This 8000 comes from the output of python -m http.server command. As you can see in above image, default port is 8000. For my case, I would enter 192.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.

Mobile browser for my case:
alt text

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. alt text
    • 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.
. . . . . . . . . . . .