Python to Share your Folders Via Web Server/http

Python to Share your Folders Via Web Server/http


If you want to share your folders and files via a HTTP server and for one reason or another don't want dirty you the hand with the configuration of apache which can be quite complicated and can make you lose some time , so believe me it's Python you're looking for, it comes with a very simple script to use that will allow you to transform any directory / folder in web server allowing you to share content with other people,'ll get them the ability to download and upload files directly from / on this directory.
The one and only software you will need to install is Python (which is not really a software but a compiler for Python - programming language - coded scripts). Python is available in two versions, Python2 and Python3, I advise you to install both side by side in order to run all the scripts without without problems, regardless of the version of Python that they use... Click here to download Python2 and Python3 from the official site.
Installation on Windows is very simple, next next next and presto you have Python installed and functional, if you use Linux or Mac, there is a good chance that you have already pre-installed Python2, you can check by running one of following commands in the Terminal:
$ python --version
Or:
$ python -V

If you want to install python3 also it is very simple, I would do a little tutorial later, meanwhile, ask Uncle Google help.

Share a directory via a web server / HTTP:

Now that Python was installed, it's time to use it to share a directory via a web server / http.
Suppose I want to share the 'Documents' directory whose path is "/ Adnane/Documents", all I have to do is open a terminal (or CMD for Windows) place me in this directory with the command:
$ cd /Adnane/Documents
and:

Download only:

Linux and Mac with python2:
$ python -m SimpleHTTPServer
Linux and Mac with python3:
$ python -m http.server
Windows with python2:
"c:\Python27\python.exe" -m SimpleHTTPServer
Windows with python3:
"c:\Python34\python.exe" -m http.erver
Note to change the figure in Red with the version that you have installed. The port used by default is 8000, you can change it by adding a space and the port you want to use after the command. Ex: $ python2 m SimpleHTTPServer 4444

Download and Upload:

To allow the upload as well as download via a web server, it's a little different but it's still very simple. Simply copy the following code which is a modified version of the default module of SipleHTTPServer that we used above, and paste it in a file and make you well to give the .py extension! me I choose to name it " serveurHTTP.py ".« .

   



You you are already placed in the directory that you want to share isn't it? cool, now run one of the following command:
Linux and Mac:
$ python /répertoire_du_script/nom_du_script.py
Windows:
"c:\Python27\python.exe" /répertoire_du_script/nom_du_script.py
This script is like I had you said based on the SipleHTTPServer python module, so automatically it also it uses 8000 as default for the web server port, and Yes you guessed it for this script also can indicate a different port after thecommand.

Access the server:

To access the server that we launched just use as url " votre_adresse_ip:le_port_utilise", it's as simple as that!
To retrieve your address internal IP run the command ipconfig for Windows or ifconfig for Linux and Mac. When to votrez public IP address, use a service like whatismyipaddress.com to know her.
EXAMPLE: 192.168.1.16:8000
Please note that if you will share the server with a person who is outside of your network must Open the port that you will use in your box internet and give it votre_ip_publique:le_port !
I guess that you already know but I'll tell you anyway, if you have a file index.html in the shared directory, this file will be executed automatically by the browser, this is very useful if you are working on a website and you want toshow your progress to your friends, colleagues or superiors.
This tutorial comes to an end, I hope that you have been useful, if yes do not hesitate to share it with your friends, see you soon!

1 comment:

  1. Interesting post, but your source code got all messed up (with quotes especially).

    ReplyDelete

Powered by Blogger.