python scp傳文件

 

  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()  

本人是菜鳥,腳本還有好多地方需要改進。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章