报错信息:UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 66-67: invalid continuation byte
这里是代码:
程序代码:
import paramiko
import os
def DownLoadFile(sftp, LocalFile, RemoteFile): # 下载当个文件
file_handler = open(LocalFile, 'wb')
print(file_handler)
sftp.get(RemoteFile, LocalFile) # 下载目录中文件
file_handler.close()
return True
def DownLoadFileTree(sftp, LocalDir, RemoteDir): # 下载整个目录下的文件
if not os.path.exists(LocalDir):
os.makedirs(LocalDir)
for file in sftp.listdir(RemoteDir):
Local = os.path.join(LocalDir, file)
Remote = os.path.join(RemoteDir, file)
if file.find(".") == -1: # 判断是否是文件
if not os.path.exists(Local):
os.makedirs(Local)
DownLoadFileTree(sftp, Local, Remote)
else: # 文件
print(file)
DownLoadFile(sftp, Local, Remote)
return "complete"
if __name__ == '__main__':
host = '192.168.0.190' # 主机
port = 22 # 端口
username = 'YL123' # 用户名
password = '123456' # 密码
sf = paramiko.Transport((host, port))
sf.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(sf)
local = 'e:\sshtest' # 本地文件
remote = '/freeSSHd/P211027178Y/' # 远程文件或目录
DownLoadFileTree(sftp, local, remote)
import os
def DownLoadFile(sftp, LocalFile, RemoteFile): # 下载当个文件
file_handler = open(LocalFile, 'wb')
print(file_handler)
sftp.get(RemoteFile, LocalFile) # 下载目录中文件
file_handler.close()
return True
def DownLoadFileTree(sftp, LocalDir, RemoteDir): # 下载整个目录下的文件
if not os.path.exists(LocalDir):
os.makedirs(LocalDir)
for file in sftp.listdir(RemoteDir):
Local = os.path.join(LocalDir, file)
Remote = os.path.join(RemoteDir, file)
if file.find(".") == -1: # 判断是否是文件
if not os.path.exists(Local):
os.makedirs(Local)
DownLoadFileTree(sftp, Local, Remote)
else: # 文件
print(file)
DownLoadFile(sftp, Local, Remote)
return "complete"
if __name__ == '__main__':
host = '192.168.0.190' # 主机
port = 22 # 端口
username = 'YL123' # 用户名
password = '123456' # 密码
sf = paramiko.Transport((host, port))
sf.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(sf)
local = 'e:\sshtest' # 本地文件
remote = '/freeSSHd/P211027178Y/' # 远程文件或目录
DownLoadFileTree(sftp, local, remote)