服务器列表文件,ztree展示远程服务器文件列表

class SFTP(paramiko.Transport):

def __init__(self, host, port=22):

self.sftp = ""

super(SFTP, self).__init__(host, port)

def connect(self, username, password):

super(SFTP, self).connect(username=username, password=password)

self.sftp = paramiko.SFTPClient.from_transport(self)

def put(self, local_path, remote_path):

self.sftp.put(local_path, remote_path)

def get(self, remote_path, local_path):

self.sftp.get(remote_path, local_path)

def is_file_exsit(self, remote_dir, file_name):

file_list = [i.filename for i in self.sftp.listdir_attr(remote_dir)]

if file_name in file_list:

return True

else:

return False

def listdir(self, remote_dir, ret_list):

file_list = self.sftp.listdir_attr(remote_dir)

for i in file_list:

data = {"name": i.filename, "children": [], "id": i.filename}

if stat.S_ISDIR(i.st_mode):

# data["iconOpen"] = "/static/img/folder_closed.png"

# data["iconClose"] = "/static/img/folder_open.png"

data["is_dir"] = True

ret_list.append(data)

child_remote_dir = remote_dir + "/" + i.filename

self.listdir(child_remote_dir, data["children"])

else:

data["icon"] = SITE_URL + "static/img/file.png"

data["is_dir"] = False

ret_list.append(data)

return ret_list

def close(self):

self.sftp.close()

super(SFTP, self).close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值