脚本如下:
# cat myscp.py #!/usr/bin/env pythonimport paramikoimport oshostname = '192.168.56.101'port = 22username = '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.plRetrieving 10_30.plRetrieving 10_28.plRetrieving 10_27.pl# ls *.pl10_27.pl 10_28.pl 10_29.pl 10_30.pl