39 Star 222 Fork 51

chuanjiao10 / kasini3000

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
k_upload2httpd.ps1 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
#建议保存编码为:bom头 + utf8
param
(
# [parameter(Mandatory = $true)]
# [ValidateNotNullOrEmpty()]
# [Alias("user")][String]$用户名,
# [parameter(Mandatory = $true)]
# [ValidateNotNullOrEmpty()]
# [Alias("pwd")][String]$密码,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$FilePath,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$httpDPath
#[String]$httpDPath = 'http://127.0.0.1:8888/?upload' # http://1.2.3.4:8888
)
if ( ($httpDPath -match '^http://') -or ($httpDPath -match '^https://') )
{
}
else
{
Write-Error "错误:目标路径错误。http://1.2.3.4:8888。退出码2"
exit 2
}
$temp99 = $httpDPath.Split(':')
if ($temp99.Length -eq 3)
{
[String]$目的ip地址 = $temp99[1].Trim('/')
[uint16]$端口 = $temp99[2].split('/')[0] -as [uint16]
# $目的ip地址
# $端口
}
else
{
Write-Error "错误:必须输入httpd端口。http://1.2.3.4:8888。退出码4"
exit 4
}
if (Test-Path -LiteralPath $FilePath.Trim())
{
}
else
{
Write-Error "错误:找不到源文件,或源路径。退出码3"
exit 3
}
$端口通了 = & 'c:\ProgramData\kasini3000\tcp--ping-v5.ps1' -MyComputerName $目的ip地址 -port $端口 -Quiet
if ($端口通了 -eq $true)
{
}
else
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:被控机端口不通。错误码24"
}
else
{
Write-Error "error:node port cloesd.exit 24"
}
exit 24
}
Try
{
Add-Type -AssemblyName 'System.Net.Http'
$client = New-Object System.Net.Http.HttpClient
$content = New-Object System.Net.Http.MultipartFormDataContent
$fileStream = [System.IO.File]::OpenRead($filePath)
$fileName = [System.IO.Path]::GetFileName($filePath)
$fileContent = New-Object System.Net.Http.StreamContent($fileStream)
$content.Add($fileContent, 'file', $fileName)
$result = $client.PostAsync($httpDPath, $content).Result
$result.EnsureSuccessStatusCode()
}
Catch
{
Write-Error $_
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:文件上传失败。错误码1"
}
else
{
Write-Error "error:File upload failed.exit 1"
}
exit 1
}
Finally
{
if ($client -ne $null)
{
$client.Dispose()
}
if ($content -ne $null)
{
$content.Dispose()
}
if ($fileStream -ne $null)
{
$fileStream.Dispose()
}
if ($fileContent -ne $null)
{
$fileContent.Dispose()
}
}
exit 0
PowerShell
1
https://gitee.com/chuanjiao10/kasini3000.git
git@gitee.com:chuanjiao10/kasini3000.git
chuanjiao10
kasini3000
kasini3000
master

搜索帮助