Data Transfer#
Warning
* Please DO NOT transfer any sensitive
data using the following methods.
To build on the previous client/server example, we can transfer file data from one machine to another.
Downloading Files#
Use the -l option to create a server to host the file:
pync -l localhost 8000 < file.in
py -m pync -l localhost 8000 < file.in
# server.py
import pync
# Be sure to open files in binary mode
# for the pync function.
with open('file.in', 'rb') as f:
pync.run('-l localhost 8000', stdin=f)
On a separate console, connect to the server to download the file:
pync localhost 8000 > file.out
py -m pync localhost 8000 > file.out
# client.py
import pync
# Be sure to open files in binary mode
# for the pync function.
with open('file.out', 'wb') as f:
pync.run('localhost 8000', stdout=f)
During the file transfer, there won’t be any progress indication. The connection will close automatically after the file has been transferred.
Uploading Files#
You can also upload files by swapping the client/server roles.
Create a server to download the file data:
pync -l localhost 8000 > file.out
py -m pync -l localhost 8000 > file.out
# server.py
import pync
# Be sure to open files in binary mode
# for the pync function.
with open('file.out', 'wb') as f:
pync.run('-l localhost 8000', stdout=f)
On a separate console, connect to the server to upload the file:
pync localhost 8000 < file.in
py -m pync localhost 8000 < file.in
# client.py
import pync
# Be sure to open files in binary mode
# for the pync function.
with open('file.in', 'rb') as f:
pync.run('localhost 8000', stdin=f)
- SEE ALSO: