Skip to content

Instantly share code, notes, and snippets.

@ashitaka1963
Created July 6, 2022 21:56
Show Gist options
  • Save ashitaka1963/061cce50e85ae9ab1b15e33514aa6c4b to your computer and use it in GitHub Desktop.
Save ashitaka1963/061cce50e85ae9ab1b15e33514aa6c4b to your computer and use it in GitHub Desktop.
[SFTP通信] paramikoを使用したSFTP通信 #paramiko
import paramiko
with paramiko.SSHClient() as client:
HOSTNAME = '127.0.0.1'
USERNAME = 'ashitaka1963'
PASSWORD = 'password'
REMOTE_PATH = '/home/ashitaka1963/test.txt'
LOCAL_PATH = '.\\bk\\bk_test.txt'
# SSH接続
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=HOSTNAME, port=22, username=USERNAME, password=PASSWORD)
# SFTP
with client.open_sftp() as sftp:
sftp.get(remotepath=REMOTE_PATH, localpath=LOCAL_PATH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment