1. #!/usr/bin/python  
  2. import pexpect  
  3. import getpass  
  4. host=raw_input('hostname: ')  
  5. remote_path=raw_input('remote_path: ')  
  6. local_file=raw_input('local_file: ')  
  7. passwd=getpass.getpass('password: ')  
  8. cmd='scp -r %s %s:%s'%(local_file,host,remote_path)  
  9. child=pexpect.spawn(cmd)  
  10. child.expect('password:')  
  11. child.sendline(passwd)  
  12. child.read()  

本人是菜鸟,脚本还有好多地方需要改进。