Last active
February 4, 2026 13:38
-
-
Save elico/d66ca33094bf3eb599d413fc1aa9e327 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param ( | |
| [string]$IP, | |
| [string]$Port, | |
| [string]$Pass, | |
| [string]$DestinationPath | |
| ) | |
| Add-Type -AssemblyName System.Windows.Forms | |
| Add-Type -AssemblyName System.Drawing | |
| # --- Logic: If any CLI args are missing, show the GUI --- | |
| if (-not $IP -or -not $Port -or -not $Pass) { | |
| $Form = New-Object System.Windows.Forms.Form | |
| $Form.Text = "Rclone Sync Setup" | |
| $Form.Size = New-Object System.Drawing.Size(350, 400) | |
| $Form.StartPosition = "CenterScreen" | |
| # (UI Controls - Using default values if not provided via CLI) | |
| $TextIP = New-Object System.Windows.Forms.TextBox | |
| $TextIP.Text = if ($IP) { $IP } else { "192.168.231.100" } | |
| $TextIP.Location = New-Object System.Drawing.Point(20, 40); $TextIP.Width = 280 | |
| $TextPort = New-Object System.Windows.Forms.TextBox | |
| $TextPort.Text = if ($Port) { $Port } else { "6060" } | |
| $TextPort.Location = New-Object System.Drawing.Point(20, 95); $TextPort.Width = 280 | |
| $TextPass = New-Object System.Windows.Forms.TextBox | |
| $TextPass.PasswordChar = '*' | |
| $TextPass.Location = New-Object System.Drawing.Point(20, 150); $TextPass.Width = 280 | |
| $DefaultDest = if ($DestinationPath) { $DestinationPath } else { Join-Path $env:USERPROFILE "MobileBackup" } | |
| $TextDest = New-Object System.Windows.Forms.TextBox | |
| $TextDest.Text = $DefaultDest | |
| $TextDest.Location = New-Object System.Drawing.Point(20, 205); $TextDest.Width = 200 | |
| # ... [Rest of UI Labels and Browse button remain same as previous version] ... | |
| # (Simplified for brevity, but assume labels and Start button are here) | |
| $StartButton = New-Object System.Windows.Forms.Button | |
| $StartButton.Text = "🚀 Start Sync"; $StartButton.Location = New-Object System.Drawing.Point(20, 260); $StartButton.Width = 280 | |
| $StartButton.DialogResult = [System.Windows.Forms.DialogResult]::OK | |
| $Form.Controls.AddRange(@($TextIP, $TextPort, $TextPass, $TextDest, $StartButton)) | |
| if ($Form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { | |
| $IP = $TextIP.Text | |
| $Port = $TextPort.Text | |
| $Pass = $TextPass.Text | |
| $DestinationPath = $TextDest.Text | |
| } else { | |
| exit | |
| } | |
| } | |
| # --- Execution Logic (Shared by CLI and GUI) --- | |
| $RemoteName = "redmi" | |
| Write-Host "Verifying connection to $IP`:$Port..." -ForegroundColor Cyan | |
| $Check = Test-NetConnection -ComputerName $IP -Port $Port -WarningAction SilentlyContinue | |
| if ($Check.TcpTestSucceeded -eq $false) { | |
| Write-Error "Connection failed! Ensure FTP server is active." | |
| exit | |
| } | |
| rclone config delete $RemoteName 2>$null | |
| rclone config create $RemoteName ftp host=$IP port=$Port user="pc" pass=$Pass | |
| $FoldersToSync = @{ | |
| "/device/DCIM" = "DCIM" | |
| "/device/Documents" = "Documents" | |
| "/device/Pictures" = "Pictures" | |
| "/device/Android/media/com.whatsapp/WhatsApp/Media" = "WhatsApp-Media" | |
| } | |
| foreach ($Folder in $FoldersToSync.GetEnumerator()) { | |
| $Dest = Join-Path $DestinationPath $Folder.Value | |
| if (!(Test-Path $Dest)) { New-Item -ItemType Directory -Path $Dest -Force | Out-Null } | |
| Write-Host "Syncing $($Folder.Key)..." -ForegroundColor Yellow | |
| rclone copy "$($RemoteName):$($Folder.Key)" $Dest --progress --ignore-errors | |
| } | |
| Write-Host "Done!" -ForegroundColor Green |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Add-Type -AssemblyName System.Windows.Forms | |
| Add-Type -AssemblyName System.Drawing | |
| # --- Create the Form --- | |
| $Form = New-Object System.Windows.Forms.Form | |
| $Form.Text = "Rclone Sync Setup" | |
| $Form.Size = New-Object System.Drawing.Size(350, 400) | |
| $Form.StartPosition = "CenterScreen" | |
| $Form.Topmost = $true | |
| # IP Address | |
| $LabelIP = New-Object System.Windows.Forms.Label | |
| $LabelIP.Text = "Mobile IP Address:" | |
| $LabelIP.Location = New-Object System.Drawing.Point(20, 20); $LabelIP.Width = 250 | |
| $Form.Controls.Add($LabelIP) | |
| $TextIP = New-Object System.Windows.Forms.TextBox | |
| $TextIP.Text = "192.168.231.100" | |
| $TextIP.Location = New-Object System.Drawing.Point(20, 40); $TextIP.Width = 280 | |
| $Form.Controls.Add($TextIP) | |
| # Port | |
| $LabelPort = New-Object System.Windows.Forms.Label | |
| $LabelPort.Text = "FTP Port:" | |
| $LabelPort.Location = New-Object System.Drawing.Point(20, 75) | |
| $Form.Controls.Add($LabelPort) | |
| $TextPort = New-Object System.Windows.Forms.TextBox | |
| $TextPort.Text = "6060" | |
| $TextPort.Location = New-Object System.Drawing.Point(20, 95); $TextPort.Width = 280 | |
| $Form.Controls.Add($TextPort) | |
| # Password | |
| $LabelPass = New-Object System.Windows.Forms.Label | |
| $LabelPass.Text = "Password:" | |
| $LabelPass.Location = New-Object System.Drawing.Point(20, 130) | |
| $Form.Controls.Add($LabelPass) | |
| $TextPass = New-Object System.Windows.Forms.TextBox | |
| $TextPass.PasswordChar = '*' | |
| $TextPass.Location = New-Object System.Drawing.Point(20, 150); $TextPass.Width = 280 | |
| $Form.Controls.Add($TextPass) | |
| # Destination Folder Selection | |
| $LabelDest = New-Object System.Windows.Forms.Label | |
| $LabelDest.Text = "Backup Destination:" | |
| $LabelDest.Location = New-Object System.Drawing.Point(20, 185) | |
| $Form.Controls.Add($LabelDest) | |
| $DefaultPath = Join-Path $env:USERPROFILE "MobileBackup" | |
| $TextDest = New-Object System.Windows.Forms.TextBox | |
| $TextDest.Text = $DefaultPath | |
| $TextDest.Location = New-Object System.Drawing.Point(20, 205); $TextDest.Width = 200 | |
| $TextDest.ReadOnly = $true | |
| $Form.Controls.Add($TextDest) | |
| $BtnBrowse = New-Object System.Windows.Forms.Button | |
| $BtnBrowse.Text = "Browse..." | |
| $BtnBrowse.Location = New-Object System.Drawing.Point(225, 203); $BtnBrowse.Width = 75 | |
| $BtnBrowse.Add_Click({ | |
| $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog | |
| $FolderBrowser.SelectedPath = $TextDest.Text | |
| if ($FolderBrowser.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { | |
| $TextDest.Text = $FolderBrowser.SelectedPath | |
| } | |
| }) | |
| $Form.Controls.Add($BtnBrowse) | |
| # Start Button | |
| $StartButton = New-Object System.Windows.Forms.Button | |
| $StartButton.Text = "🚀 Start Sync" | |
| $StartButton.Location = New-Object System.Drawing.Point(20, 260); $StartButton.Width = 280; $StartButton.Height = 40 | |
| $StartButton.BackColor = "LightGreen" | |
| $StartButton.DialogResult = [System.Windows.Forms.DialogResult]::OK | |
| $Form.Controls.Add($StartButton) | |
| # --- Process Results --- | |
| if ($Form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { | |
| $RemoteName = "redmi" | |
| $HostIP = $TextIP.Text | |
| $Port = $TextPort.Text | |
| $Pass = $TextPass.Text | |
| $LocalBase = $TextDest.Text | |
| $User = "pc" | |
| # --- NEW: Connectivity Check --- | |
| Write-Host "Verifying connection to $HostIP on port $Port..." -ForegroundColor Cyan | |
| $Check = Test-NetConnection -ComputerName $HostIP -Port $Port -WarningAction SilentlyContinue | |
| if ($Check.TcpTestSucceeded -eq $false) { | |
| [System.Windows.Forms.MessageBox]::Show("Could not connect to the mobile device at $HostIP`:$Port.`n`nMake sure the FTP server is running on your phone and you are on the same Wi-Fi.", "Connection Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error) | |
| exit | |
| } | |
| Write-Host "Connection successful!" -ForegroundColor Green | |
| $FoldersToSync = @{ | |
| "/device/DCIM" = "DCIM" | |
| "/device/Documents" = "Documents" | |
| "/device/Pictures" = "Pictures" | |
| "/device/Android/media/com.whatsapp/WhatsApp/Media" = "WhatsApp-Media" | |
| } | |
| Write-Host "Configuring Rclone..." -ForegroundColor Cyan | |
| rclone config delete $RemoteName 2>$null | |
| rclone config create $RemoteName ftp host=$HostIP port=$Port user=$User pass=$Pass | |
| foreach ($Folder in $FoldersToSync.GetEnumerator()) { | |
| $RemotePath = "$($RemoteName):$($Folder.Key)" | |
| $Destination = Join-Path $LocalBase $Folder.Value | |
| if (!(Test-Path $Destination)) { | |
| New-Item -ItemType Directory -Path $Destination -Force | Out-Null | |
| } | |
| Write-Host "Syncing $($Folder.Key) to $Destination..." -ForegroundColor Yellow | |
| rclone copy $RemotePath $Destination --progress --ignore-errors | |
| } | |
| Write-Host "`nAll sync tasks finished successfully!" -ForegroundColor Green | |
| Pause | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment