-
Notifications
You must be signed in to change notification settings - Fork 1
/
paramiko-download.py
33 lines (30 loc) · 1.01 KB
/
paramiko-download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
#coding:utf-8
import paramiko
import os
import datetime
hostname='192.168.3.121'
username='root'
password='redhat'
port=22
local_dir='/tmp/local/'
remote_dir='/tmp/remote/'
if __name__=="__main__":
try:
t=paramiko.Transport((hostname, port))
t.connect(username=username,password=password)
sftp=paramiko.SFTPClient.from_transport(t)
#files=os.listdir(local_dir)
files=os.listdir(remote_dir)
for f in files:
print ''
print '####################################################'
print 'Beginning to download file %s.' % datetime.datetime.now()
print 'Downloading file:',os.path.join(remote_dir,f)
sftp.get(os.path.join(remote_dir,f), os.path.join(local_dir,f))
#sftp.put(os.path.join(local_dir,f), os.path.join(remote_dir,f))
print 'Upload file success %s.' % datetime.datetime.now()
print ''
except Exception:
print "Error! Please check it."
t.close()