脚本如下:
# cat myscp.py #!/usr/bin/env python import paramiko import os hostname = ‘192.168.56.101‘ port = 22 username = ‘root‘ password = ‘111111‘ dir_path = ‘/root/perl‘ if __name__ == "__main__": t = paramiko.Transport((hostname, port)) t.connect(username=username, password=password) sftp = paramiko.SFTPClient.from_transport(t) files = sftp.listdir(dir_path) for f in files: print ‘Retrieving‘, f sftp.get(os.path.join(dir_path, f), f) t.close()
执行结果如下:
# python myscp.py Retrieving 10_29.pl Retrieving 10_30.pl Retrieving 10_28.pl Retrieving 10_27.pl # ls *.pl 10_27.pl 10_28.pl 10_29.pl 10_30.pl
本文出自 “天道酬勤” 博客,请务必保留此出处http://lavenliu.blog.51cto.com/5060944/1689184
原文地址:http://lavenliu.blog.51cto.com/5060944/1689184