欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Python實(shí)現(xiàn)的遠(yuǎn)程文件自動(dòng)打包并下載功能示例-創(chuàng)新互聯(lián)

本文實(shí)例講述了Python實(shí)現(xiàn)的遠(yuǎn)程文件自動(dòng)打包并下載功能。分享給大家供大家參考,具體如下:

10多年專(zhuān)注成都網(wǎng)站制作,成都定制網(wǎng)站,個(gè)人網(wǎng)站制作服務(wù),為大家分享網(wǎng)站制作知識(shí)、方案,網(wǎng)站設(shè)計(jì)流程、步驟,成功服務(wù)上千家企業(yè)。為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù),專(zhuān)注于成都定制網(wǎng)站,高端網(wǎng)頁(yè)制作,對(duì)邊坡防護(hù)網(wǎng)等多個(gè)方面,擁有多年的網(wǎng)站維護(hù)經(jīng)驗(yàn)。

一 點(diǎn)睛

在Linux系統(tǒng)集群運(yùn)營(yíng)當(dāng)中,時(shí)常需要批量遠(yuǎn)程執(zhí)行Linux命令,并且雙向同步文件的操作。

本示例通過(guò)使用spawn()方法執(zhí)行ssh、scp 命令的思路來(lái)實(shí)現(xiàn)。

二 代碼

import pexpect
import sys
ip="192.168.0.104"
user="root"
passwd="123456"
target_file="/data/test.txt"
child = pexpect.spawn('/usr/bin/ssh', [user+'@'+ip])
fout = file('mylog.txt','w')
child.logfile = fout
try:
  child.expect('password: ')
  child.sendline(passwd)
  child.expect('#')
  child.sendline('tar -czf /data/test.tar.gz '+target_file)
  child.expect('#')
  print child.before
  child.sendline('exit')
  fout.close()
except pexpect.EOF:
  print "expect EOF1"
except pexpect.TIMEOUT:
  print "expect TIMEOUT1"
child = pexpect.spawn('/usr/bin/scp', [user+'@'+ip+':/data/test.tar.gz','/home'])
fout = file('mylog.txt','a')
child.logfile = fout
try:
  child.expect('(?i)password')
  child.sendline(passwd)
  child.expect(pexpect.EOF)
except pexpect.EOF:
  print "expect EOF2"
except pexpect.TIMEOUT:
  print "expect TIMEOUT2"

分享標(biāo)題:Python實(shí)現(xiàn)的遠(yuǎn)程文件自動(dòng)打包并下載功能示例-創(chuàng)新互聯(lián)
URL鏈接:http://chinadenli.net/article22/ejsjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、微信小程序網(wǎng)站內(nèi)鏈、移動(dòng)網(wǎng)站建設(shè)、App設(shè)計(jì)動(dòng)態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)