Hands-on Lab·Python Automation for IT
Python SFTP File Transfers
`open_sftp()` on a connected client gives you a full filesystem API over the same connection - put, get, stat, listdir, and an `open()` that reads a remote file with no local copy. The parts worth knowing are the ones that are not obvious: `confirm=True` is a size check and not a checksum, an upload is only atomic if you rename it, there is no `walk` or `rmtree`, and half the errors arrive with no errno at all.
Remote Hosts and CI/CD Guide 33 of 39 Intermediate
- Python3.14.4
- Control nodeUbuntu 26.04 LTS
- Managed hostsRHEL 10.0
- requests2.34.2
- paramiko5.0.0
- pytest9.1.1
- PyYAML6.0.3
- boto3 / botocore1.43.78
- TimeAbout 20 min
- Reviewed24 August 2026
Written against the versions above. paramiko 5.0.0. `posix_rename` needs the server to support the `posix-rename@openssh.com` extension, which OpenSSH has had for many years; the fallback matters for other servers.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Control node - every script in this path runs here | 2 Core | 4 GB | 50 GB |
| RHCSA-A01 | 192.168.0.31 | RHEL 10.0 | Managed host - reached over SSH from the control node | 2 Core | 4 GB | 50 GB |
| RHCSA-B01 | 192.168.0.33 | RHEL 10.0 | Second managed host - so an inventory has more than one row | 2 Core | 4 GB | 50 GB |
Before you start
- guide 31 - the client this opens a channel on.
- guide 15 - the same atomic-write argument, locally.
- guide 10 - and why posixpath rather than os.path here.
-
A file up, and the same file back
-
What confirm= is actually doing
-
A partial upload, and why the destination name matters
-
Listing, statting and reading in place
-
Walking a remote tree, which SFTP does not do for you
-
The errors, and the ones with no errno at all
-
A progress callback
-
And the same job with scp, for comparison
-
Cleaning up, on both ends