How to upload a file using SSH in Python

Uploading a file using SSH uploads a local file to a remote directory over a secure connection.

Solution for How to upload a file using SSH in Python : You can use paramiko.SSHClient() to upload a file using SSH Call paramiko.SSHClient() to create a new SSHClient. Call paramiko.SSHClient.set_missing_host_key_policy(policy) with policy as paramiko.AutoAddPolicy() to allow the Python script to SSH to a remote server with unknown SSH keys. Call paramiko.SSHClient.connect(host, port, username, password) to connect the client to the server host:port with the credentials username and password. Call paramiko.SSHClient.open_sftp() to return a paramiko.SFTPClient and open an SFTP connection on the remote server. Call paramiko.SFTPClient.put(localpath, targetpath) to upload the local file at localpath to the target path at targetpath. Call paramiko.SFTPClient.close() and paramiko.SSHClient.close() to close the connections.


how-to-upload-a-file-using-ssh-in-python