代码拉取完成,页面将自动刷新
同步操作将从 chuanjiao10/kasini3000 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#建议保存编码为:bom头 + utf8
param
(
[Alias("ipaddress")][String]$目的ip地址 = $global:当前被控机_ip.ip,
[Alias("port")][uint16]$端口 = $global:当前被控机_ip.端口,
[String]$LiteralPath,
[String]$Path,
[ValidateNotNullOrEmpty()][String]$Destination,
[Switch]$Recurse
#缩水封装
)
if (($LiteralPath -eq '') -and ($Path -eq ''))
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:源文件,源目录为空。退出码6"
}
else
{
Write-Error "error:Source file, or source directory is empty .exit 6"
}
exit 6
}
if (($LiteralPath -ne '') -and ($Path -ne ''))
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:-LiteralPath,-Path,只能输入其一。退出码7"
}
else
{
Write-Error "error:-LiteralPath,-Path,Only one of them can be entered .exit 7"
}
exit 7
}
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
& 'c:\ProgramData\kasini3000\0k_source.ps1'
}
if ($IsLinux -eq $True)
{
& '/etc/kasini3000/0k_source.ps1'
}
Write-Verbose '从主控机到被控机,复制文件开始'
if ($global:当前被控机_ip -eq $null)
{
Write-Error "错误:当前被控机 ${global:当前被控机_ip} 为空"
exit 1
}
if ($global:当前被控机_ip.length -gt 1)
{
Write-Error "错误:当前被控机 ${global:当前被控机_ip} 数量太多"
exit 2
}
if ((Test-Path -LiteralPath $LiteralPath) -or (Test-Path -Path $Path))
{
}
else
{
Write-Error "错误:找不到源文件,或源目录。退出码4"
exit 4
}
$win = 'win7','win8','win10','win2008r2','win2012r2','win2016','win2019'
$linux = 'centos7','centos8','debian8','debian9','debian10','ubuntu1404','ubuntu1604','ubuntu1804','alpine','ubuntu2004','Amazon Linux 2','kylin v10'
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
if ( $global:当前被控机_ip.被控机os类型 -in $win)
{
if ( ($端口 -eq '') -or ($端口 -eq $null) )
{
$端口 = 5985
}
try
{
Test-WSMan -ComputerName $目的ip地址 -Port $端口 -ErrorAction stop
}
catch
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:目的ip地址【${目的ip地址}】端口不通。错误码22"
}
else
{
Write-Error "error:node port closed :【${目的ip地址}】.exit 22"
}
exit 22
}
finally
{
}
& 'zd只读nodelist文件.ps1'
$当前被控机 = $global:所有被控机 | Where-Object { $_.ip -eq $目的ip地址 }
if ($当前被控机.ip -ne $目的ip地址)
{
Write-Error "错误:当前被控机获取失败 ${当前被控机}"
exit 23
}
$PSRemoting服务器用户名 = $当前被控机.用户名
$用户名2 = "${目的ip地址}\${PSRemoting服务器用户名}"
$密码明文 = $当前被控机.当前密码
$密码密文 = ConvertTo-SecureString $密码明文 -AsPlainText -Force
$用户名和密码捆绑后的授权信息 = New-Object System.Management.Automation.PSCredential ($用户名2,$密码密文)
Write-Verbose '使用密码,连接w2w5985开始'
$private:连接3 = New-PSSession -ComputerName $目的ip地址 -Port $端口 -Credential $用户名和密码捆绑后的授权信息
if ($private:连接3 -eq $null)
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:使用密码,在${目的ip地址}上连接w2w5985失败。退出码21"
}
else
{
Write-Error "error:Connection failed: ${被控机ip地址} .exit 21"
}
exit 21
}
Write-Verbose '连接成功。现在开始测试Destination目录存在否:'
$Destination存在否 = Invoke-Command -Session $private:连接3 -ScriptBlock { Test-Path $args[0] } -ArgumentList $Destination
if ($Destination存在否 -eq $true)
{
}
else
{
Remove-PSSession -Session $private:连接3
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:找不到目标目录。错误码5"
}
else
{
Write-Error "error:The target directory could not be found.exit 5"
}
exit 5
}
Write-Verbose '连接成功。现在开始复制文件:'
if ($LiteralPath -eq '')
{
if ($Recurse -eq $True)
{
Copy-Item -ToSession $private:连接3 -Path $Path -Destination $Destination -Force -Recurse
}
else
{
Copy-Item -ToSession $private:连接3 -Path $Path -Destination $Destination -Force
}
}
else
{
if ($Recurse -eq $True)
{
Copy-Item -ToSession $private:连接3 -LiteralPath $LiteralPath -Destination $Destination -Force -Recurse
}
else
{
Copy-Item -ToSession $private:连接3 -LiteralPath $LiteralPath -Destination $Destination -Force
}
}
Write-Verbose '复制文件完成,即将断开连接。'
Remove-PSSession -Session $private:连接3
}
if ( $global:当前被控机_ip.被控机os类型 -in $linux)
{
if ( $PSVersionTable.psversion.major -ge 6)
{
}
else
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:在win中连接linux,依赖powershell 6,或以上版本。错误码12"
}
else
{
Write-Error "error:need powershell version 6 or higher.exit 12"
}
exit 12
}
if ( ($端口 -eq '') -or ($端口 -eq $null) )
{
$端口 = 22
}
Write-Verbose '使用ssh秘钥1,连接w2l开始'
[string]$private:temp011 = ssh.exe -l root -i "$env:USERPROFILE\.ssh\id_rsa" ${目的ip地址} -p $端口 -o PasswordAuthentication=no 'date' *>&1
Write-Verbose $private:temp011
if ( $private:temp011.ToLower().Contains('Permission denied'.ToLower()) )
{
$秘钥1连接成功 = $false
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Verbose "错误:使用ssh秘钥1,在${目的ip地址}上连接w2l失败"
}
else
{
Write-Verbose "error:ssh-key-file1 login failed:${目的ip地址}"
}
}
else
{
$秘钥1连接成功 = $true
}
if ( $private:temp011.ToLower().Contains('timed out'.ToLower()) )
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:使用ssh秘钥1,在${目的ip地址}上w2l连接超时。退出码13"
}
else
{
Write-Error "error:ssh-key-file1 login timeout: ${被控机ip地址} .exit 13"
}
exit 13
}
if ($秘钥1连接成功 -eq $true)
{
$private:连接1 = New-PSSession -HostName ${目的ip地址} -Port $端口 -UserName root -KeyFilePath "$env:USERPROFILE\.ssh\id_rsa"
Write-Verbose '连接成功。现在开始测试Destination目录存在否:'
$Destination存在否 = Invoke-Command -Session $private:连接1 -ScriptBlock { Test-Path $args[0] } -ArgumentList $Destination
if ($Destination存在否 -eq $true)
{
}
else
{
Remove-PSSession -Session $private:连接1
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:找不到目标目录。错误码5"
}
else
{
Write-Error "error:The target directory could not be found.exit 5"
}
exit 5
}
Write-Verbose '【连接1】连接成功。现在开始复制文件:'
if ($LiteralPath -eq '')
{
if ($Recurse -eq $True)
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接1 -Path $Path -Destination $Destination -Force -Recurse
}
else
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接1 -Path $Path -Destination $Destination -Force
}
}
else
{
if ($Recurse -eq $True)
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接1 -LiteralPath $LiteralPath -Destination $Destination -Force -Recurse
}
else
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接1 -LiteralPath $LiteralPath -Destination $Destination -Force
}
}
Write-Verbose '【连接1】复制文件完成,即将断开连接。'
Remove-PSSession -Session $private:连接1
Start-Sleep -Seconds 1
}
else
{
Write-Verbose '使用ssh秘钥2,连接w2l开始'
[string]$private:temp012 = ssh.exe -l root -i "${global:kasini3000目录}\ssh_key_files_old1\id_rsa" ${目的ip地址} -p $端口 -o PasswordAuthentication=no 'date' *>&1
Write-Verbose $private:temp012
if ( $private:temp012.ToLower().Contains('Permission denied'.ToLower()) )
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:使用ssh秘钥2,在${目的ip地址}上连接w2l失败。错误码15"
}
else
{
Write-Error "error:ssh-key-file2 login failed${目的ip地址}.exit 15"
}
exit 15
}
$private:连接2 = New-PSSession -HostName ${目的ip地址} -Port $端口 -UserName root -KeyFilePath "${global:kasini3000目录}\ssh_key_files_old1\id_rsa"
$Destination存在否 = Invoke-Command -Session $private:连接2 -ScriptBlock { Test-Path $args[0] } -ArgumentList $Destination
if ($Destination存在否 -eq $true)
{
}
else
{
Remove-PSSession -Session $private:连接2
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:找不到目标目录。错误码5"
}
else
{
Write-Error "error:The target directory could not be found.exit 5"
}
exit 5
}
Write-Verbose '【连接2】连接成功。现在开始复制文件:'
if ($LiteralPath -eq '')
{
if ($Recurse -eq $True)
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接2 -Path $Path -Destination $Destination -Force -Recurse
}
else
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接2 -Path $Path -Destination $Destination -Force
}
}
else
{
if ($Recurse -eq $True)
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接2 -LiteralPath $LiteralPath -Destination $Destination -Force -Recurse
}
else
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接2 -LiteralPath $LiteralPath -Destination $Destination -Force
}
}
Write-Verbose '【连接2】复制文件完成,即将断开连接。'
Remove-PSSession -Session $private:连接2
Start-Sleep -Seconds 1
}
}
}
if ($IsLinux -eq $True)
{
if ( $global:当前被控机_ip.被控机os类型 -in $win)
{
Write-Error "无法从【linux主控机】复制文件到【win被控机】"
exit 3
}
if ( $global:当前被控机_ip.被控机os类型 -in $linux)
{
if ( ($端口 -eq '') -or ($端口 -eq $null) )
{
$端口 = 22
}
Write-Verbose '使用ssh秘钥1,连接l2l开始'
[string]$private:temp011 = ssh -l root -i '/root/.ssh/id_rsa' ${目的ip地址} -p $端口 -o PasswordAuthentication=no 'date' *>&1
Write-Verbose $private:temp011
if ( $private:temp011.ToLower().Contains('Permission denied'.ToLower()) )
{
$秘钥1连接成功 = $false
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Verbose "错误:使用ssh秘钥1,在${目的ip地址}上连接l2l失败"
}
else
{
Write-Verbose "error:ssh-key-file1 login failed:${目的ip地址}"
}
}
else
{
$秘钥1连接成功 = $true
}
if ( $private:temp011.ToLower().Contains('timed out'.ToLower()) )
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:使用ssh秘钥1,在${目的ip地址}上l2l连接超时。退出码13"
}
else
{
Write-Error "error:ssh-key-file1 login timeout: ${被控机ip地址} .exit 13"
}
exit 13
}
if ($秘钥1连接成功 -eq $true)
{
$private:连接5 = New-PSSession -HostName ${目的ip地址} -Port $端口 -UserName root -KeyFilePath '/root/.ssh/id_rsa'
Write-Verbose '连接成功。现在开始测试Destination目录存在否:'
$Destination存在否 = Invoke-Command -Session $private:连接5 -ScriptBlock { Test-Path $args[0] } -ArgumentList $Destination
if ($Destination存在否 -eq $true)
{
}
else
{
Remove-PSSession -Session $private:连接5
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:找不到目标目录。错误码5"
}
else
{
Write-Error "error:The target directory could not be found.exit 5"
}
exit 5
}
Write-Verbose '【连接5】连接成功。现在开始复制文件:'
if ($LiteralPath -eq '')
{
if ($Recurse -eq $True)
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接5 -Path $Path -Destination $Destination -Force -Recurse
}
else
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接5 -Path $Path -Destination $Destination -Force
}
}
else
{
if ($Recurse -eq $True)
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接5 -LiteralPath $LiteralPath -Destination $Destination -Force -Recurse
}
else
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接5 -LiteralPath $LiteralPath -Destination $Destination -Force
}
}
Write-Verbose '【连接5】复制文件完成,即将断开连接。'
Remove-PSSession -Session $private:连接5
Start-Sleep -Seconds 1
}
else
{
Write-Verbose '使用ssh秘钥2,连接l2l开始'
[string]$private:temp012 = ssh -l root -i "${global:kasini3000目录}/ssh_key_files_old1/id_rsa" ${目的ip地址} -p $端口 -o PasswordAuthentication=no 'date' *>&1
Write-Verbose $private:temp012
if ( $private:temp012.ToLower().Contains('Permission denied'.ToLower()) )
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:使用ssh秘钥2,在${目的ip地址}上连接l2l失败。错误码15"
}
else
{
Write-Error "error:ssh-key-file2 login failed${目的ip地址}.exit 15"
}
exit 15
}
$private:连接6 = New-PSSession -HostName ${目的ip地址} -Port $端口 -UserName root -KeyFilePath "${global:kasini3000目录}/ssh_key_files_old1/id_rsa"
Write-Verbose '连接成功。现在开始测试Destination目录存在否:'
$Destination存在否 = Invoke-Command -Session $private:连接6 -ScriptBlock { Test-Path $args[0] } -ArgumentList $Destination
if ($Destination存在否 -eq $true)
{
}
else
{
Remove-PSSession -Session $private:连接6
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:找不到目标目录。错误码5"
}
else
{
Write-Error "error:The target directory could not be found.exit 5"
}
exit 5
}
Write-Verbose '【连接6】连接成功。现在开始复制文件:'
if ($LiteralPath -eq '')
{
if ($Recurse -eq $True)
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接6 -Path $Path -Destination $Destination -Force -Recurse
}
else
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接6 -Path $Path -Destination $Destination -Force
}
}
else
{
if ($Recurse -eq $True)
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接6 -LiteralPath $LiteralPath -Destination $Destination -Force -Recurse
}
else
{
#$env:LANG = 'en_US.UTF-8'
Copy-Item -ToSession $private:连接6 -LiteralPath $LiteralPath -Destination $Destination -Force
}
}
Write-Verbose '【连接6】复制文件完成,即将断开连接。'
Remove-PSSession -Session $private:连接6
Start-Sleep -Seconds 1
}
}
}
Write-Verbose '从主控机到被控机,复制文件完成'
exit 0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。