Sharing files in the network- the easy way!

Tips and Tricks for Networking

Moderator: jkerr82508

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Sharing files in the network- the easy way!

Postby viking60 » 01 Apr 2015, 21:31

Image
Often when I want to share files with someone else in the household it can be done with ssh or samba if it is set up correctly....

Then you have the problem of different users on different machines and you have therefore no right to access the file etc...

In this situation people tend to use clouds like Dropbox etc easy to upload and download on another PC. And you have probably shared it with a loot of other people too in that process unless you have encrypted your data. ... and that again is not so easy..

So here I am then with a nice spreadsheet that I need to share with my wife's PC how can I make this easily accessible to her - fast?

Python comes to my rescue +1
I simply go the the directory (in a terminal) where the files that I want to share are and type:

Code: Select all

python -m http.server

This only works for Arch based distros - for other distros see below

Then I ask my wife to go to my PC with the browser on port 8000 something like this

Code: Select all

http//192.168.0.123:8000

You will find the ip of your computer with

Code: Select all

ip addr
good old ifconfig will work too

And all the files in the directory where i Started the server are presented to her :jackpot
Image
Image
The default port is 8000 but you can specify another one if you like:

Code: Select all

python -m http.server 9999

This is super easy and super fast and works like this on Arch and Arch based distros like Manjaro etc.
Image

If you use Mageia, Debian - or most other distros - you must alter the command slightly:

Code: Select all

python -m SimpleHTTPServer

The rest is the same.
The difference in commands has to do with what version of python you are using. I believe python 3 uses http.server and python 2 uses SimpleHTTPServer. You can check your python version with

Code: Select all

python -V

Once you have shared the file; just stop the server with CTRL+c

The next time you need to share something fast - simply go to the directory where the files are and start the server again.

If you have Linux there is nothing to install - it works right out of the box in most cases.

More here
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Sharing files in the network- the easy way!

Postby viking60 » 02 Apr 2015, 02:41

You would not want to use this as a permanent sharing solution on an internet connected machine :hand:
This will share your files quick and easy to one person. If 10 persons try to access the files at the same time it will not work - this is a one at the time solution.

To make a permanent server with python you can go to the directory you want to share and type:

Code: Select all

twistd web --path .

twistd web will then start and you can access with the browser as described above.
Image
It looks a bit better and your terminal will not be occupied with "live action". Here all people can access the files at the same time.


This will start the server on the default port of 8080.


To stop this server I have to do a

Code: Select all

 kill `cat twistd.pid`


This is the python2 way - If you want to use python3 (as you would on bleeding edge distros) then you need to install python-twisted (not python2-twisted) and start the server with:

Code: Select all

twistd3 web --path .


If you want the server to be on a different port than 8080 (because it is already in use) then you can specify the port like this:
:A

Code: Select all

twistd3 web --port "tcp:port=9000" --path .

In this case the server will be on port 9000.

If you want to make a permanent file server with twistd web you should probably read up a bit on it. It has lots of configuration possibilities.

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Sharing files in the network- the easy way! - Windows

Postby viking60 » 18 Apr 2015, 09:34

On Windows python is not native so to make this work on a laptop with Windows 7 I downloaded and installed python 3 from here
This was placed in C:\Python34
Next I opened a cmd window and ran

Code: Select all

set path=%path%;C:\Python34\

This is a one time setup.
If you want to add Python to your path permanently:
Select 'System' from the Control Panel, selecting the 'Advanced' tab, the 'Environment Variables' button and then finding the PATH
Add this at the end:

Code: Select all

;C:\python34


After that I simply typed

Code: Select all

python -m http.server

And that did server the content of my Windows lap nicely.
Image

I don't have to fiddle with Samba of Ftp or anything else to easily share my Windows files either :jackpot
Here you see the root of a Windows 7 Laptop.
:A
Image


So my Linux and Windows boxes have the ability to share data fast. They speak the same language and no admin hassle. Windows firewall will pop up and ask you that one question once and that is all.
As with Linux the server is running in the CMD window and does show any IP that access it. It is stopped with CTRL+C like in Linux.
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Sharing files in the network- the easy way!

Postby viking60 » 29 Jul 2016, 23:48

After having received a landslide of votes to make this a Wiki for Manjaro in their forums :-D I have finally committed it:
:A
https://wiki.manjaro.org/index.php?titl ... e_easy_way

It is not as thorough as this tutorial - right here - but still... :smug

..Thought you guys should be the first to know +1
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Sharing files in the network- the easy way!

Postby viking60 » 02 May 2018, 11:39

Python is updated so often on Manjaro that it is hard to keep the permanent file server up so here is another way of doing it:

Code: Select all

python -c 'from twisted.web.server import Site; from twisted.web.static import File; from twisted.internet import reactor; reactor.listenTCP(8000, Site(File("."))); reactor.run()'


Here the permanent file server will be on port 8000.

To run the server in the background just copy the line above into a terminal and run it. Then break it off with <CTRL+C> and type <bg> to start it in the background.
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Sharing files in the network- the easy way!

Postby viking60 » 01 Nov 2018, 10:59

The permanent file server now requires you to install python-twisted and python-service-identity (at least on Manjaro)
Like this in Arch and Manjaro

Code: Select all

sudo pacman -S python-twisted python-service-identity


It is still as easy as pie to use it though :-D
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"


Return to “Networking”