How to transfer a file between two connected computers in python?

I do not know if this was the answer earlier (I looked online, but could not find it), but how can I send a file (.exe, if possible) over the network to another computer that is connected to the network? I tried sockets, but I could only send strings, and I tried to learn ftplib, but I don’t understand this at all, or if ftp is what I am looking for, so I completely froze. Any input is appreciated (moreover, if someone can explain FTP, is it like a socket? All the examples that I saw do not have a server program to which the client can connect.)

+6
source share
4 answers

Some simplified code examples for the sender:

if os.path.exists(df):
  with open(df, 'rb') as f:
    packet = f.read(blocksize)

    while packet != '':
      conn.send(packet)

      packet = f.read(blocksize)

Where:

df = 'path/to/data/file'
blocksize = 8192 # or some other size packet you want to transmit.  
                 # Powers of 2 are good.
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+5
source

. Python3

http.server . SO SimpleHTTPServer http.server python3.

python -m http.server

Python2:

SimpleHTTPServer :

python -m SimpleHTTPServer

... 8000. - , .

IP- , ( Ubuntu) ifconfig, :

$ ifconfig
enp0s31f6 Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
          inet addr:10.0.0.3  Bcast:10.0.0.255  Mask:255.255.255.0

windows ipconfig.

: http://10.0.0.3:8000.

B. SSH, paramiko SFTP .

+8
+3

ZeroMQ .

.

ZMQ "party" can be written in any main language and for this ZMQ-powered software, it doesn't matter which other end he wrote.

From your site:

It provides you with sockets that contain entire messages in different sorts such as intraprocessor, interprocessor, TCP and multicast. You can connect N-to-N sockets with patterns such as fanout, pub-sub, task distribution, and request-response.

+3
source

All Articles