1 :  [root@Virtual python] # clear
   2 :  [root@Virtual python] # python paramiko_get.py
   3 / usr / local / lib / python2. 6 / site - packages / pycrypto - 2.3 - py2. 6 - linux - i686.egg / Crypto / Util / randpool.py: 40 : RandomPool_DeprecationWarning: This application uses RandomPool, which is BROKEN in older releases.  See http: / / www.pycrypto.org / randpool - broken
   4 2012 - 03 - 20 16 : 32 : 03.067956
   5 :  receiving  / tmp / test / 2.txt
   6 2012 - 03 - 20 16 : 32 : 03.068104
   7 2012 - 03 - 20 16 : 32 : 03.073088
   8 2012 - 03 - 20 16 : 32 : 03.073147
   9 :  receiving  / tmp / test / 1.txt
  10 2012 - 03 - 20 16 : 32 : 03.073244
  11 2012 - 03 - 20 16 : 32 : 03.079213
  12 :  [root@Virtual python] # cat paramiko_get.py
  13 #!/usr/bin/env python
  14 import paramiko
  15 import os
  16 import datetime
  17 :  hostname = '172.28.191.19'
  18 :  username = 'root'
  19 :  password = 'shangha'
  20 :  port = 22
  21 :  dir_remote = '/tmp/put'
  22 :  local_path = '/tmp/test/'
  23 if __name__ = = "__main__" :
  24 :   #    try:
  25 :          paramiko.util.log_to_file( 'paramiko.log' )
  26 :          t = paramiko.Transport((hostname,port))
  27 :          t.connect(username = username,password = password)     登录远程主机
  28 :          sftp = paramiko.SFTPClient.from_transport(t)
  29 :          files = sftp.listdir(dir_remote)          读取远程机器文件夹内文件
  30 :          for f in files:
  31 :
  32 :                  print datetime.datetime.now()
  33 :                  print 'receiving ' ,os.path.join(local_path,f)
  34 #               print 'Retrieving',f
  35 :                  print datetime.datetime.now()                   打印开始时间
  36 :                  sftp.get(os.path.join(dir_remote,f),os.path.join(local_path,f))     开始下载
  37 #               sftp.put(os.path.join(local_path,f),os.path.join(dir_remote,f))
  38 :                  print datetime.datetime.now()                  打印结束时间
  39 :       #except Exception:
  40 #       print "error!"
  41 :          t.close()
  42 :  [root@Virtual python] #