← Go Back
To run this code you must first install the pysftp module by running in the terminal:
How to Upload a File Using SFTP
Using the pysftp library:import pysftp
# Address or IP of the SFTP server.
host = "ftp.my-site.com"
# Authentication.
username = "my-user"
password = "my-password-123"
# Make the connection.
with pysftp.Connection(host, username=username, password=password) as sftp:
# Change the directory to the remote folder where you want
# upload the file.
with sftp.cd("/home/public_html"):
# Upload the local file hello.txt to the server.
sftp.put("hello.txt")
To run this code you must first install the pysftp module by running in the terminal:
pip install pysftp