weixin_39546312
weixin_39546312
2020-12-08 18:16

use pexpect to scp "large" size file, we need to sleep to get the correct size of files?

I try to transfer files from the remote site to the local site by using:


tempChannel = pexpect.spawn('scp root:/largeSizeFile /local_folder')
tempChannel.expect('assword:')
tempChannel.sendline(my_password)

If I do this without sleep, I will get a "blank" file, so I try to do:


tempChannel = pexpect.spawn('scp root:/largeSizeFile /local_folder')
tempChannel.expect('assword:')
tempChannel.sendline(my_password)
time.sleep(1)

and it works well. Then I try to shorten the sleep time, say

time.sleep(0.05)
I will get "part" of the content of the file instead of intact file. Therefore, it looks like the sleep time does really matter in this case. Do I wrongly use the function? or how do I solve this issue if I don't wanna freeze my runtime.

btw, when I try


pexpect.run('scp root:/largeSizeFile /local_folder', events={"assword:", "my_password"})

it will freeze for a while and then finishes without correctly transferring.

Thanks!

该提问来源于开源项目:pexpect/pexpect

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答