Created
July 6, 2022 21:56
-
-
Save ashitaka1963/061cce50e85ae9ab1b15e33514aa6c4b to your computer and use it in GitHub Desktop.
[SFTP通信] paramikoを使用したSFTP通信 #paramiko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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