1螳 朱..
import paramiko
from base64 import decodebytes
host = "192.168.100.100"
port = 22
id = "id"
pw = "pw"
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.load_system_host_keys()
client.connect(host, username=id, password=pw, port=port, timeout=14400) # 殊 蟆曙 timeout 誤讌 朱 蠍覦 伎.
tr = client.get_transport()
#tr.default_max_packet_size = 214748364 #願 觜殊 .
tr.default_window_size = 2147483647 #願 誤讌 朱 覓 襴 豐 10kb
paramiko.sftp_file.SFTPFile.MAX_REQUEST_SIZE = pow(2, 22) #願 誤讌 朱 貅 伎.
sftp = client.open_sftp()
remonte_file_path = '/remote_dir/sample.log.gz'
local_file_path = '/local_dir/sample.log.gz'
sftp.get(remonte_file_path, local_file_path)
client.close()
襴 蟇 覈 れ企
import os
import sys
import paramiko
from stat import S_ISDIR
host = "192.168.100.100"
port = 22
id = "id"
pw = "pw"
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.load_system_host_keys()
client.connect(host, username=id, password=pw, port=port, timeout=14400) #timeout 誤讌 朱 蠍覦 伎.
tr = client.get_transport()
#tr.default_max_packet_size = 214748364 #願 觜殊 .
tr.default_window_size = 2147483647 #願 誤讌 朱 覓 襴 豐 10kb
paramiko.sftp_file.SFTPFile.MAX_REQUEST_SIZE = pow(2, 22) #願 誤讌 朱 貅 伎.
sftp = client.open_sftp()
remonte_file_path = sys.argv[1] #/remote_dir/
local_file_path = sys.argv[2] #/local_dir/
def sftp_walk(remotepath):
path=remotepath
files=[]
folders=[]
for f in sftp.listdir_attr(remotepath):
if S_ISDIR(f.st_mode):
folders.append(f.filename)
else:
files.append(f.filename)
if files:
yield path, files
for folder in folders:
new_path=os.path.join(remotepath,folder)
for x in sftp_walk(new_path):
yield x
os.system("mkdir " + local_file_path)
for path, files in sftp_walk(remonte_file_path):
for file in files:
print(os.path.join(os.path.join(path,file)))
sftp.get(os.path.join(os.path.join(path,file)), local_file_path+file)
client.close()