- #!/usr/bin/python
- import pexpect
- import getpass
- host=raw_input('hostname: ')
- remote_path=raw_input('remote_path: ')
- local_file=raw_input('local_file: ')
- passwd=getpass.getpass('password: ')
- cmd='scp -r %s %s:%s'%(local_file,host,remote_path)
- child=pexpect.spawn(cmd)
- child.expect('password:')
- child.sendline(passwd)
- child.read()
- ~
本人是菜鳥,腳本還有好多地方需要改進。