The script is as follows:
# cat myscp.py #!/usr/bin/env pythonimport paramikoimport oshostname = ' 192.168.56.101 ' port = 22username = ' Root ' pa ssWOrd = ' 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 sft P.get (Os.path.join (Dir_path, F), F) t.close ()
The results of the implementation are as follows:
# 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
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/44/wKiom1XfxYSSxUbzAAjw7pLI6_w181.jpg "title=" python _paramiko_scp.png "alt=" Wkiom1xfxyssxubzaajw7pli6_w181.jpg "/>
This article is from the "Tiandaochouqin" blog, make sure to keep this source http://lavenliu.blog.51cto.com/5060944/1689184
Using the Paramiko module to copy remote files to a local