-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFile-Share.ps1
More file actions
44 lines (36 loc) · 1.44 KB
/
File-Share.ps1
File metadata and controls
44 lines (36 loc) · 1.44 KB
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
################################# !File Sharing via HTTP Server and Cloudflare Tunnel #################################
param (
[Parameter(Mandatory=$true)]
[string]$FilePath
)
if (!(Get-Command -Name cloudflared -ErrorAction SilentlyContinue) -or
!(Get-Command -Name simple-http-server -ErrorAction SilentlyContinue)) {
Write-Host "`ncloudflared or simple-http-server is not installed." -ForegroundColor Red
Write-Host "Please install both of them first before running this script." -ForegroundColor Red
return
}
#* Start the server
Start-Job -Name "MyServer" -ScriptBlock {
$path = $using:FilePath
if (Test-Path $path -PathType Leaf) {
$path = Split-Path $path
}
Set-Location $path
simple-http-server.exe -u -i -t 4 -c $path
}
Start-Sleep -Seconds 5 # wait for the job to start
Start-Job -Name "MyTunnel" -ScriptBlock {
cloudflared.exe tunnel --url http://0.0.0.0:8000
}
Start-Sleep -Seconds 5 # wait for the job to start
Write-Host "`nServer and Tunnel are running!`n" -ForegroundColor Magenta
#* To see the output of the server:
Receive-Job -Name MyServer -Keep
Start-Sleep -Seconds 5 # wait for the job to start
Receive-Job -Name MyTunnel -Keep
Write-Host "`nPress ENTER to stop both and exit..." -ForegroundColor Yellow -NoNewline
Read-Host
#* Stop the jobs
Stop-Job -Name "MyServer", "MyTunnel"
Remove-Job -Name "MyServer", "MyTunnel"
Write-Host "`nJobs stopped and cleaned up.`n" -ForegroundColor Magenta