Manjaro Общий доступ к файлам с помощью Python

Общий доступ к файлам с помощью Python

From Manjaro
Revision as of 17:59, 26 December 2022 by Krotesk (talk | contribs) (Created page with "===Остановка сервера=== После того, как вы поделились файлами, просто остановите сервер с помощью...")
Other languages:
English • ‎русский

Введение

Существует множество способов совместного использования файлов в сети. Samba обычно используется для межсетевого обмена. Эти методы проще и быстрее настроить. Их можно использовать для обмена файлами между компьютером, смартфоном или планшетом.

Вы можете поделиться с:

  • OSX
  • Windows
  • Android

он будет работать на всех платформах.

Он предназначен для ситуаций, когда вам нужно быстро поделиться чем-то, и не рекомендуется в качестве части вашей обычной инфраструктуры.


Установка

В этом и заключается его прелесть - ничего не нужно устанавливать. Этот метод будет работать прямо из коробки, потому что Manjaro поставляется с Python 3, позволяющий легко и быстро обмениваться файлами в вашей сети.


Использование

Откройте терминал на компьютере, содержащем файлы, которыми вы хотите поделиться, перейдите в каталог, где находятся файлы, которыми вы хотите поделиться, например ˝/home; затем введите:

python -m http.server

Теперь перейдите на компьютер, телефон или вкладку, на которую должны прийти файлы, и откройте браузер.

Sharing.jpg

.

В поле url браузера введите

http://IP_общедоступного_компьютера:8000

Чтобы найти IP-адрес компьютера, с которого вы хотите открыть общий доступ, введите:

ip addr

Что-то вроде этого:

http://192.168.55.123:8000

В результате будет выведен список всех файлов в каталоге компьютера с общим доступом.:


Теперь вы можете скачивать или открывать файлы. - Это так просто.

Обмен с других систем с вашим компьютером с Manjaro

Поскольку вы можете захотеть поделиться файлами с других компьютеров с вашим компьютером Manjaro; они могут иметь Python2 (Это относится к Debian, Mageia и некоторым другим дистрибутивам. В Windows вам нужно будет сначала установить Python).

Здесь нужно написать другую команду. Откройте терминал и напишите:

python -m SimpleHTTPServer

Перейдите на компьютер с Manjaro и откройте url как описано выше, и вы получите доступ к файлам.

Если вы хотите использовать другой порт, а не 8000 по умолчанию - например, 9000 - вы можете ввести его следующим образом:

python -m http.server 9000

Остановка сервера

После того, как вы поделились файлами, просто остановите сервер с помощью команды

CTRL+c

It is as easy as that!

Some final remarks

This server will live in your terminal and occupy it until you cancel it. You can see every transaction. You can only share with one computer at the time. It is a fast and super easy solution for that.

Note
This is not a permanent file server.

Creating a permanent file server (still the easy way)

You would not want to use the sharing solution above (permanently) on an internet connected machine. It 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 - it is a one at the time solution. So let's work some magic to fix that!

Installation

Install python-twisted and python-service-identity (they are in the extra repo).

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

Using it

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

twistd3 web --path . 
Twisted.jpg

twistd web will then start and you can access in the browser with:

http://localhost:8080/

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.

If you need to set the server to a different port then you can start the server like this:

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

In this case the server will be on port 9000.



Python is often updated so if you get any errors running the command above you can alternatively try:

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()'

break it off with CTRL+Z and then type bg to start it in the background.

Here the server will be on port 8000 you can change it to your liking.

Stopping the server

To stop this server you can type:

kill `cat twistd.pid`

Now you have a permanent file server.

Note
If you want to share from other servers to (not from) Manjaro then you may need to install python2-twisted and start the server with twistd web --path . systems

It's as easy as that!

Cookies help us deliver our services. By using our services, you agree to our use of cookies.