- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
- Python 3 Advanced Tutorial
- Python 3 - Classes/Objects
- Python 3 - Reg Expressions
- Python 3 - CGI Programming
- Python 3 - Database Access
- Python 3 - Networking
- Python 3 - Sending Email
- Python 3 - Multithreading
- Python 3 - XML Processing
- Python 3 - GUI Programming
- Python 3 - Further Extensions
How to copy files from one server to another using Python?
The easiest way to copy files from one server to another over ssh is to use the scp command. For calling scp you'd need the subprocess module.
import subprocess p = subprocess.Popen(["scp", "my_file.txt", "username@server:path"]) sts = os.waitpid(p.pid, 0)
You need the waitpid call to wait for the copying to complete.
Another solution is to open a ssh connection and use the scp module.
from paramiko import SSHClient from scp import SCPClient ssh = SSHClient() ssh.load_system_host_keys() ssh.connect('user@server:path') with SCPClient(ssh.get_transport()) as scp: scp.put('my_file.txt', 'my_file.txt') # Copy my_file.txt to the server
- Related Articles
- How to copy files from one folder to another using Python?
- How to copy certain files from one folder to another using Python?
- How to copy tables or databases from one MySQL server to another MySQL server?
- How to copy items from one location to another location using PowerShell?
- How we can copy Python modules from one system to another?
- How to copy Docker images from one host to another without using a repository?
- How to copy files to a new directory using Python?
- How to copy a table from one MySQL database to another?
- How to copy rows from one table to another in MySQL?
- How to copy the palette from one image to another using imagepalettecopy() function in PHP?
- How to copy a collection from one database to another in MongoDB?
- Copy values from one array to another in Numpy
- How to copy multiple files in PowerShell using Copy-Item?
- How to copy files from host to Docker container?
- How to move a file from one folder to another using Python?