-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.ps1
executable file
·44 lines (38 loc) · 978 Bytes
/
send.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Sender/Client
# send -ip 10.1.1.1 -port 2222 -file commands.ps1
Param(
[Parameter(Mandatory=$true)][string]$ip,
[Parameter(Mandatory=$true)][int]$port,
[Parameter(Mandatory=$true)][string]$file
)
function Base64Encode-File
{
param
(
[Parameter(Mandatory = $true)]
[string]$file
)
process
{
$c = Get-Content $file -Encoding Byte
return [System.Convert]::ToBase64String($c)
}
}
Try {
$TcpClient=New-Object System.Net.Sockets.TcpClient $ip, $port
$GetStream = $TcpClient.GetStream()
$StreamWriter = New-Object System.IO.StreamWriter $GetStream
$fileName = Split-Path $file -leaf
$data = Base64Encode-File $file
$file= "$fileName#$data"
$file | %{
$StreamWriter.Write($_)
}
Write-Host "File `"$file`" encoded to clipboard in $($data.Length) bytes"
$StreamWriter.Dispose()
$GetStream.Dispose()
$TcpClient.Dispose()
}
Catch {
"Receive Message failed with: `n" + $Error[0]
}