Sharing Files Just Got Easier


You can use the SimpleHTTPServer module that comes with Python to share files. Even though the thought of using Python SimpleHTTPServer may seem complicated it is not. It is so straightforward that you do not need to have any prior knowledge on Python programming. 

Using Python SimpleHTTPServer with Mac

Follow the instructions below to work with the Python SimpleHTTPServer:

Sharing the files

Follow the instructions below to share files with a remote user using the Python SimpleHTTPServer:

Step 1: Share the file

  1. Download the Python script (simpleHTTPServer.py.zip) from here.
  2. Unzip the simpleHTTPServer.py.zip file.
  3. Navigate to the directory that has the folders and files that you wish to share.
    For example:
    cd /Users/MH/Documents/APIM_2.5.0/Share-zone
  4. Copy the simpleHTTPServer.py file to the folder that contains the files that need to be shared.
    For example:
    Copy the simpleHTTPServer.py file from the downloads folder to the Share-zone folder,  which is the folder that you are going to share.
    cp ~/Downloads/simpleHTTPServer.py
  5. Compress the files that you wish to share.
    tar -cvzf <compressed-folder-name>.tar.gz <folder-to-be-copied>/
    
    For example:
    tar -cvzf apim.tar.gz apim/
    
    For more information on the command used to compress the files, go to https://www.cs.duke.edu/~ola/courses/programming/tar.html
  6. Start the Python simpleHTTPServer.
    python simpleHTTPServer.py
    Sample output:
    MH-MacBook-Air:APIM_2.5.0 MH$ python simpleHTTPServer.py
    serving at port 8000
    10.100.7.36 - - [25/Jun/2018 12:04:54] "GET / HTTP/1.1" 200 -
    10.100.7.36 - - [25/Jun/2018 12:04:57] "GET /apim.tar.gz HTTP/1.1" 200 -

Step 2: Share your details with the other party

  1. Identify your IP address.
    You can retrieve your IP address by executing the following command:
    ifconfig
    
  2. Identify the port that the Python simpleHTTPServer is using.
    When the Python server starts, the port that it is using will be printed in the terminal.
    For example:
    MH-MacBook-Air:APIM_2.5.0 MH$ python simpleHTTPServer.py
    
    serving at port 8000
    
    10.100.7.36 - - [25/Jun/2018 12:04:54] "GET / HTTP/1.1" 200 -
    10.100.7.36 - - [25/Jun/2018 12:04:57] "GET /apim.tar.gz HTTP/1.1" 200 -
    
    In this case the Python simpleHTTPServer is using port 8000.
Share the above details with the other party whom you wish to share the files with.

Retrieving the shared file

  1. Access the respective serving URL via your browser in order to be able to download the file that is being shared with you.
    http://<sender-IP-address>:<serving-port>
    For example:
    http://10.100.0.113:8000
  2. Click on the compressed file (e.g., apim.tar.gz).
    It will get downloaded automatically.

Stopping the server

After the other party has finished copying all the file, navigate to the terminal that the Python simpleHTTPServer is running and press the following keys to stop the server.
Ctrl +C
. . .
I hope that this article was useful to you. 

Acknowledgements



Comments