「已注销」 2017-07-19 07:35 采纳率: 77.4%
浏览 1188
已采纳

如何在一台本地可以上网的linux虚拟机中写一个脚本上传文件到腾讯云?

如何在一台本地可以上网的linux虚拟机中写一个脚本上传文件到腾讯云?急需啊,谢谢大佬了,我想让一个文件1分钟上传一次到云服务器,并覆盖之前的旧的

  • 写回答

1条回答 默认 最新

  • 呆的久 2017-07-19 08:49
    关注

    用scp上传,你可以自己写个bash,也可以用python.

     #!/usr/bin/env python
    
    import pexpect
    import sys
    import time
    
    INTERVAL   = 3 # one hour
    
    scpOpt     = ' -oStrictHostKeyChecking=no' + ' -q ' # no host key check, quite mode
    fileName   = 'test.txt'
    remoteHost = '10.10.10.10'
    remoteDir  = '/home/jupyter'
    userName   = 'jupyter'
    userPasswd = 'admin'
    
    # scp command
    cmd = 'scp' + scpOpt + '{0} {1}@{2}:{3}'.format(fileName,userName,remoteHost,remoteDir)
    while(True):
        # upload file to remote server
        shell = pexpect.spawn(cmd)
        i = shell.expect([pexpect.TIMEOUT, 'assword:'])
        if i == 0:
            print "scp timeout"
            sys.exit(-1)
    
        # send the password
        shell.sendline(userPasswd)
    
        # wait for upload complete
        while(shell.isalive()):
            print "shell is alive, wait 200 ms"
            time.sleep(0.2)
    
        # sleep 1 hour
        time.sleep(INTERVAL)
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?