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