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

如何在一台本地可以上网的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)
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退