日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

堡垒机如何传输文件_mac 堡垒机传文件

發布時間:2023/12/20 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 堡垒机如何传输文件_mac 堡垒机传文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

安裝zssh

brew install zssh

上傳文件

zssh登陸上跳板機

在跳板機上ssh到相應服務器

在服務器上cd至相應要放上傳文件的目錄

rz -bye //在遠程服務器的相應目錄上運行此命令,表示做好接收文件的準備

ctrl+@ //運行上面命令后,會出現一些亂碼字符,不要怕,按此組合鍵,進入zssh

zssh > //這里切換到了本地機器

zssh > pwd //看一下本地機器的目錄在那

zssh > ls //看一下有那些文件

zssh > sz 123.txt //上傳本地機器的當前目錄的123.txt到遠程機器的當前目錄

下載文件

sz filename //在遠程機器上,啟動sz, 準備發送文件,看到一堆亂碼,不要怕,這會按下組合鍵

cd 切換到合適的目錄

zssh > rz //接住對應的文件

#!/usr/bin/env python

# coding=utf-8

from optparse import OptionParser

import paramiko

import os,sys,time

"""

這個腳本的作用是實現堡壘機模式下,文件上傳

"""

parser = OptionParser()

parser.add_option('-j', '--jumperuser', dest='jumperuser', help='Company jumper machine account like wutengfei, ..')

parser.add_option('-u', '--username', dest='username', help='Target machine account like wutengfei, ..')

parser.add_option('-p', '--port', dest='port', help='Target machine port')

parser.add_option('-m', '--hostname', dest='hostname', help='Target machine ip address like 192.168.246.168')

parser.add_option('-l', '--localpath', dest='localpath', help="Client local file path like '/Users/test.py'")

parser.add_option('-d', '--destpath', dest='destpath', help="Jumper server file path like '/tmp/test.py'")

parser.add_option('-t', '--targetpath', dest='targetpath', help="remote server file path like '/tmp/test.py'")

(opts,args) = parser.parse_args()

#定義跳板機信息

jumpername = "jumper.shuju.com" # 跳板機ip/域名

jumperport = 22 # 跳板機ssh端口

paramiko.util.log_to_file('syslogin.log')

class JumperInfo(object):

"""

將文件從客戶端上傳至跳板機

"""

def __init__(self,username,localpath,destpath):

self.username = str(username)

self.localpath = str(localpath)

self.destpath = str(destpath)

def jumper_ftp(self,jumperuser,localpath,destpath):

private_key = os.path.expandvars('$HOME/.ssh/id_rsa')

private_key = paramiko.RSAKey.from_private_key_file(private_key)

t = paramiko.Transport(('jumper.shuju.com', 22))

t.connect(username=jumperuser, pkey=private_key)

sftp = paramiko.SFTPClient.from_transport(t)

sftp.put(localpath,destpath)

sftp.close()

passinfo='\'s password: '

class Jumper_put(JumperInfo):

"""

將跳板機上的文件上傳至目標機

"""

def __init__(self,hostname,username,port,targetpath):

self.hostname = str(hostname)

self.username = str(username)

self.port = str(port)

self.targetpath = str(targetpath)

def jumper_scp(self,jumperuser,destpath,username,hostname,targetpath,port):

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

privatekey = os.path.expandvars('$HOME/.ssh/id_rsa')

key = paramiko.RSAKey.from_private_key_file(privatekey)

ssh.connect(hostname='jumper.shuju.com', username=jumperuser, port=22, pkey=key)

channel = ssh.invoke_shell()

channel.settimeout(10)

buff = ''

resp = ''

channel.send('scp ' + ' ' + '-P' + ' ' + port + ' ' + destpath + ' ' + username + '@' + hostname + ':' + targetpath + '\n')

while not buff.endswith('$ '):

resp = channel.recv(9999)

if not resp.find(passinfo)==-1:

print 'Error info: Authentication failed.'

channel.close()

ssh.close()

sys.exit()

buff += resp

print buff

channel.close()

ssh.close()

def main():

jumper_ssh = JumperInfo(username=opts.jumperuser,localpath=opts.localpath,destpath=opts.destpath)

jumper_ssh.jumper_ftp(opts.jumperuser,opts.localpath,opts.destpath)

target_ssh = Jumper_put(hostname=opts.hostname,username=opts.username,port=opts.port,targetpath=opts.targetpath)

target_ssh.jumper_scp(opts.jumperuser,opts.destpath,opts.username,opts.hostname,opts.targetpath,opts.port)

if __name__ == '__main__':

if opts.jumperuser == None or opts.username == None or opts.hostname == None or opts.localpath == None or opts.destpath == None or opts.targetpath == None or opts.port == None:

parser.print_help()

exit(-1)

main()

總結

以上是生活随笔為你收集整理的堡垒机如何传输文件_mac 堡垒机传文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。