【Python】scpでリモートサーバー(外部サーバー)のファイルを取得したり削除したりできるクラスを作ってみました。
事前に以下のパッケージをインストールする必要があります。
pip install paramiko scp
SCPClientWrapperクラス
ソースコードは以下の通りです。
SCPClientWrapperクラスの使い方
login = {
"host": "host",
"port": 22,
"user": "username",
"pass": "password"
}
with SCPClientWrapper(login) as scp:
# リモートサーバーのファイルを取得
spc.get("remote_path", "local_path")
# リモートサーバーのファイルを削除
scp.rm("remote_path")
# リモートサーバーのファイル一覧を取得
scp.find_file("remote_path")
