Skip to content

Instantly share code, notes, and snippets.

@silkyland
Created July 13, 2026 12:39
Show Gist options
  • Select an option

  • Save silkyland/5628b1df09ff14be9a4d0e3df6d1f444 to your computer and use it in GitHub Desktop.

Select an option

Save silkyland/5628b1df09ff14be9a4d0e3df6d1f444 to your computer and use it in GitHub Desktop.
# ================================================================
# SFTP Setup Script for ais-pronet.com (via Cloudflare Tunnel)
# Uses TCP proxy mode because FileZilla doesn't support ProxyCommand
# ================================================================
$ErrorActionPreference = "Stop"
$SftpHost = "sftp.ais-pronet.com"
$LocalPort = 2223 # different port so it won't clash with marketthaipro's 2222
Write-Host ""
Write-Host "===================================================" -ForegroundColor Cyan
Write-Host " SFTP Setup for $SftpHost" -ForegroundColor Cyan
Write-Host "===================================================" -ForegroundColor Cyan
Write-Host ""
# --- Step 1: Check/Install cloudflared ---
Write-Host "[1/3] Checking cloudflared..." -ForegroundColor Yellow
$cfInstalled = Get-Command cloudflared -ErrorAction SilentlyContinue
if ($cfInstalled) {
$version = & cloudflared --version 2>&1 | Select-Object -First 1
Write-Host " cloudflared already installed: $version" -ForegroundColor Green
} else {
Write-Host " cloudflared not found. Installing via winget..." -ForegroundColor Yellow
try {
winget install --id Cloudflare.cloudflared --accept-source-agreements --accept-package-agreements -e
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host " Installed successfully" -ForegroundColor Green
} catch {
Write-Host " ERROR: winget failed. Please install manually from:" -ForegroundColor Red
Write-Host " https://github.com/cloudflare/cloudflared/releases/latest" -ForegroundColor Red
exit 1
}
}
# --- Step 2: Create tunnel launcher script ---
Write-Host ""
Write-Host "[2/3] Creating tunnel launcher..." -ForegroundColor Yellow
$launcherDir = "$env:USERPROFILE\ais-pronet-sftp"
$launcherPath = "$launcherDir\start-tunnel.ps1"
$shortcutPath = "$env:USERPROFILE\Desktop\Start SFTP Tunnel (ais-pronet).lnk"
if (-not (Test-Path $launcherDir)) {
New-Item -ItemType Directory -Path $launcherDir -Force | Out-Null
}
$launcherContent = @"
`$Host.UI.RawUI.WindowTitle = "SFTP Tunnel - $SftpHost"
Write-Host "===================================================" -ForegroundColor Cyan
Write-Host " SFTP Tunnel to $SftpHost" -ForegroundColor Cyan
Write-Host "===================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Starting tunnel on localhost:$LocalPort ..." -ForegroundColor Yellow
Write-Host "Browser will open for authentication (first time / after expiry)" -ForegroundColor Gray
Write-Host ""
Write-Host "Once you see 'Listening on 127.0.0.1:$LocalPort':" -ForegroundColor Green
Write-Host " 1. Open FileZilla" -ForegroundColor White
Write-Host " 2. Host: localhost" -ForegroundColor Cyan
Write-Host " 3. Port: $LocalPort" -ForegroundColor Cyan
Write-Host " 4. Protocol: SFTP" -ForegroundColor Cyan
Write-Host " 5. Enter your username and password" -ForegroundColor White
Write-Host ""
Write-Host "!! Keep this window OPEN while using FileZilla !!" -ForegroundColor Yellow
Write-Host " Closing this window disconnects the tunnel." -ForegroundColor Gray
Write-Host ""
Write-Host "---------------------------------------------------" -ForegroundColor Gray
cloudflared access tcp --hostname $SftpHost --url localhost:$LocalPort
"@
Set-Content -Path $launcherPath -Value $launcherContent -Encoding UTF8
Write-Host " Created launcher: $launcherPath" -ForegroundColor Green
# --- Step 3: Create Desktop shortcut ---
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($shortcutPath)
$Shortcut.TargetPath = "powershell.exe"
$Shortcut.Arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$launcherPath`""
$Shortcut.WorkingDirectory = $launcherDir
$Shortcut.IconLocation = "powershell.exe,0"
$Shortcut.Description = "Start SFTP tunnel to $SftpHost"
$Shortcut.Save()
Write-Host " Created desktop shortcut: Start SFTP Tunnel (ais-pronet)" -ForegroundColor Green
Write-Host ""
Write-Host "===================================================" -ForegroundColor Cyan
Write-Host " Setup complete!" -ForegroundColor Green
Write-Host "===================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "HOW TO USE (every time you want to upload files):" -ForegroundColor White
Write-Host " 1. Double-click 'Start SFTP Tunnel (ais-pronet)' icon on your Desktop" -ForegroundColor Cyan
Write-Host " 2. Wait for the line: Listening on 127.0.0.1:$LocalPort" -ForegroundColor Cyan
Write-Host " 3. First time: a browser window opens -> enter your email -> check inbox for PIN -> enter PIN" -ForegroundColor Cyan
Write-Host " 4. Open FileZilla and connect with:" -ForegroundColor Cyan
Write-Host " Protocol: SFTP" -ForegroundColor White
Write-Host " Host: localhost" -ForegroundColor White
Write-Host " Port: $LocalPort" -ForegroundColor White
Write-Host " User/Pass: (provided separately by admin)" -ForegroundColor White
Write-Host " 5. When done, close the PowerShell window to disconnect" -ForegroundColor Cyan
Write-Host ""
Read-Host "Press Enter to exit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment