脚本如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# 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()
|
执行结果如下:
1
2
3
4
5
6
7
8
|
# 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
|
版权声明:原创作品,如需转载,请注明出处。否则将追究法律责任