How do I transfer data from one computer to another using Python?

Install simplehttpserver

Using the SimpleHTTPServer that Python implements we can share files via HTTP from GNU/Linux, Windows and probably MacOS with whoever we want and stop sharing them as soon as it is no longer necessary. It is as simple as opening a console in the folder we want to share (If you use Dolphin as a file browser you can press SHIFT+F4 to open a console in the current folder) and type the following:

Then you tell the other person to put in his web browser http://tuIP:8000 (for example: http://192.168.1.33:8000) and he will be able to see all the files that you have in that folder, when you finish you close the console and nobody will be able to access.

Note that 8000 is the port chosen to mount the mini HTTP server, but it does not have to be that one, it can be the one you want. And to clarify that if you want to share files with someone who is not in your local network (via internet), you only have to open the port 8000, or the one you have chosen, in your router so that anyone in the world can access. Don’t forget to give him your external IP and not your local IP, because otherwise he will never be able to access. To know your external IP you can use services like http://www.whatsmyip.org/.

Send image via python sockets

Some time ago I needed to transfer files from my test computer, which at the time had Ubuntu 11.10, to my main computer, where I was using Ubuntu 10.04 LTS, in order to make some changes in the partitions of the first one. After experimenting with many methods, some that didn’t work and others that did but very slowly, I managed to find a solution that convinced me for being simple, infallible and that allows to reach really tremendous speeds.

First we must make sure that both computers are connected to the local network. Then we open a console on the server computer and enter the directory containing the file or folder we are going to send. Then we do the same on the client computer, accessing the directory where the files to be received will be saved (by default they are saved in the user folder). In both cases the command to use will be similar to this one:

Substituting, of course, the name once again. When we do that we will see that the console will answer us with the message Press any key to start receiving data; which translated would be Press any key to start receiving data. Press any key and the file will start transferring.

Send files via python socket

Python provides as standard a large set of functions to perform operations with files and folders, so that it is possible to develop a cross-platform file explorer without using additional packages. The main modules are os and os.path, in a more general aspect, and shutil, specialized in high-level operations for handling documents and directories. You will notice that many of these functions are common in most of your programs.

One of the most used functions in this area is getcwd() (current working directory), as its name indicates, it returns the current path from where our script is executed, or the Python installation directory in the case of the interpreter.

In Python 2.x, if the argument is a unicode object, the resulting items will keep this encoding, if possible. Similarly, Python 3 allows you to specify a directory of type bytes.

The mkdir (make directory) and makedirs functions allow you to create folders by specifying their location and, on some systems, permissions (0o777 by default, i.e. all operations – see File system permissions).

Send python files

pythonNow, copy the following code and paste it into the Python interpreter, in the command line interface. Then press Enter (several times, if necessary) to execute it. You can also save the code as a file named scrape_quotes.py in the Scraper web project folder. If you do so, you will be able to run the Python script with the command python scrape_quotes.py.As a final result after running the code, in your Scraper web project folder there should be a file named zitate.csv. This file contains a table with quotes and authors and you can open it with any spreadsheet program of your choice.# Importing modules

csv_writer.writerows(zip(quotes, authors))Using Python packages for scrapingNo two web scraping projects are the same. Sometimes you just want to check if there have been changes to a page and sometimes you want to perform complex evaluations, among other options. Python gives you a wide range of packages to choose from:pip3 install <package></package> from <package> import <module></module></package>These are some of the most commonly used packages in web scraping projects: