INNER CODE UNIT · Python
sftp_list
sky22333/ansible-ui · app.py:514
def sftp_list(host_id):
"""获取 SFTP 文件列表"""
path = request.args.get('path', '/')
host = db.get_host(host_id)
if not host:
return jsonify({'error': 'Host not found'}), 404
try:
with sftp_client_for_host(host) as sftp:
file_list = []
for entry in sftp.listdir_attr(path):
file_list.append({
'name': entry.filename,
'type': 'directory' if stat.S_ISDIR(entry.st_mode) else 'file',
'size': entry.st_size,
'mtime': entry.st_mtime
})