我目前是IT服务的实习生,被要求使用Python构建可在Linux环境中运行的基于Web的应用程序。该Web应用程序必须符合WSGI,并且我不能使用任何框架。
目前我的问题是我想将一个变量设置为所述目录中的文件列表。因此,我可以通过打印一个表格来列出这些文件,每行都是一个文件。
我知道os.listdir(),但是找不到在远程服务器上使用它的方法(考虑到Google搜索向我显示的内容,应该不是这种情况)。
我尝试了一个os.system(ssh root @ someip:/ path / to / dir /),但是作为python doc状态,我无法获得想要的输出,因为它返回了一些整数...
下面是我的一段脚本。
#ip is = to the ip of the server I want to list.
ip = 192..............
directory = "/var/lib/libvirt/images/"
command = "ssh root@"+ip+" ls "+directory
dirs = os.system(command)
files = ""
table_open = "<table>"
table_close = "</table>"
table_title_open = "<th>Server: "
table_title_close = "</th>"
tr_open = "<tr>"
tr_close = "</tr>"
td_open = "<td>"
td_close = "</td>"
input_open = "<input type='checkbox' name='choice' value='"
input_close = "'>" …Run Code Online (Sandbox Code Playgroud)