0
我想写一个函数,它会ssh到远程主机和目录中的每个文件,处理它。Python - 如何运行for循环通过ssh访问的目录中的文件?
例如,我对对回路电流的功能是:
import fnmatch, os
def process_logfiles_in_remote_directory(remotedir):
for filename in os.listdir(remotedir):
if fnmatch.fnmatch(filename, '*.log'):
filename = os.path.join(remotedir, filename)
## Do something here...
如何换行上述功能的ssh连接,事中的这行:
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect("www.remotehost.com", username="admin", password="testing")
stdin, stdout, stderr = ssh_client.exec_command(process_logfiles_in_remote_directory('/tmp'))
ssh_client.close()
[在python中通过sftp连接后如何列出目录中的所有文件夹和文件](http://stackoverflow.com/questions/12295551/how-to-list-all-the-folders-和文件,在最目录后连接通) – kawadhiya21