https://docs.paramiko.org/en/stable/api/sftp.html
transport = paramiko.Transport(('192.168.110.51', 22))
try:
#transport.connect(username='root', password='123456')
ftp = paramiko.SFTPClient.from_transport(transport)
except Exception as e:
print(e)
print('远程连接失败...')
#下载中
ftp.get(from_file, to_file)
ftp.chdir(to_dir)
ftp.chdir('..')
ftp.mkdir(item)
try:
sftp.stat(path)
print("exist")
except IOError:
print("not exist")
def ftp_file_exists(self, fname):
try:
# 需要使用全路径检测
self.ftp.stat(fname)
return True
except IOError:
return False
# 获取远程的子目录列表
lst = self.ftp.listdir(self.X['remote_dir'])