FTP Server on Wndows

FTP Server on Wndows



Server Side
- Edit -> Settings -> Passive Settings -> Port range 50000-51000 / Add Public IP Address
- Open ports 21,990,50000-51000

Client Side
- Copy the backup script (Attached Below)
- Setup task schedular for desirable time

Script
Change IP add. of server, username and password for the website and also remote and local path.
NOTE : If it doesn't work run power shell as admin and execute the following command.

  1. Set-ExecutionPolicy -ExecutionPolicy RemoteSigned


  1. param (
  2.     # Use Generate Session URL function to obtain a value for -sessionUrl parameter.
  3.     $sessionUrl = "ftp://USRE@PASS@SERVERIP/",
  4.     $whileloopcounter = 1,
  5.     #[Parameter(Mandatory = $True)]
  6.     $localPath="LOCALPATH",
  7.     #[Parameter(Mandatory = $True)]
  8.     $remotePath="REMOTEPATH",
  9.     [Switch]
  10.     $delete,
  11.     [Switch]
  12.     $beep,
  13.     [Switch]
  14.     $continueOnError,
  15.     $sessionLogPath = $Null,
  16.     $interval = 0,
  17.     [Switch]
  18.     $pause
  19. )

  20. try
  21. {
  22.     # Load WinSCP .NET assembly
  23.     $assemblyPath = if ($env:WINSCP_PATH) { $env:WINSCP_PATH } else { $PSScriptRoot }
  24.     Add-Type -Path (Join-Path $assemblyPath "WinSCPnet.dll")

  25.     # Setup session options
  26.     $sessionOptions = New-Object WinSCP.SessionOptions
  27.     $sessionOptions.ParseUrl($sessionUrl)

  28.     $session = New-Object WinSCP.Session
  29.     
  30.     # Optimization
  31.     # (do not waste time enumerating files, if you do not need to scan for deleted files)
  32.     if ($delete) 
  33.     {
  34.         $localFiles = Get-ChildItem -Recurse -Path $localPath
  35.     }

  36.     try
  37.     {
  38.         $session.SessionLogPath = $sessionLogPath

  39.         Write-Host "Connecting..."
  40.         $session.Open($sessionOptions)

  41.         while ($whileloopcounter)
  42.         {
  43.             Write-Host "Synchronizing changes..."
  44.             $result =
  45.                 $session.SynchronizeDirectories(
  46.                     [WinSCP.SynchronizationMode]::Local, $localPath, $remotePath, $delete)

  47.             $changed = $False

  48.             if (!$result.IsSuccess)
  49.             {
  50.               if ($continueOnError)
  51.               {
  52.                 Write-Host "Error: $($result.Failures[0].Message)"
  53.                 $changed = $True
  54.               }
  55.               else
  56.               {
  57.                 $result.Check()
  58.               }
  59.             }

  60.             # Print updated files
  61.             foreach ($download in $result.Downloads)
  62.             {
  63.                 Write-Host "$($download.Destination) <= $($download.FileName)"
  64.                 $changed = $True
  65.             }

  66.             if ($delete)
  67.             {
  68.                 # scan for removed local files (the $result does not include them)
  69.                 $localFiles2 = Get-ChildItem -Recurse -Path $localPath

  70.                 if ($localFiles)
  71.                 {
  72.                     $changes =
  73.                         Compare-Object -DifferenceObject $localFiles2 `
  74.                             -ReferenceObject $localFiles
  75.                 
  76.                     $removedFiles =
  77.                         $changes |
  78.                         Where-Object -FilterScript { $_.SideIndicator -eq "<=" } |
  79.                         Select-Object -ExpandProperty InputObject

  80.                     # Print removed local files
  81.                     foreach ($removedFile in $removedFiles)
  82.                     {
  83.                         Write-Host "$removedFile deleted"
  84.                         $changed = $True
  85.                     }
  86.                 }

  87.                 $localFiles = $localFiles2
  88.             }

  89.             if ($changed)
  90.             {
  91.                 if ($beep)
  92.                 {
  93.                     [System.Console]::Beep()
  94.                 }
  95.             }
  96.             else
  97.             {
  98.                 Write-Host "No change."
  99.             }
  100.             
  101.             #Write-Host "Waiting for $interval seconds, press Ctrl+C to abort..."
  102.             $wait = [int]$interval
  103.             # Wait for 1 second in a loop, to make the waiting breakable
  104.             while ($wait -gt 0)
  105.             {
  106.                 Start-Sleep -Seconds 1
  107.                 $wait--
  108.             }
  109.             $whileloopcounter = 0
  110.             Write-Host
  111.         }
  112.     }
  113.     finally
  114.     {
  115.         Write-Host "Disconnecting..."
  116.         # Disconnect, clean up
  117.         $session.Dispose()
  118.     }
  119. }
  120. catch
  121. {
  122.     Write-Host "Error: $($_.Exception.Message)"
  123. }

  124. # Pause if -pause switch was used
  125. if ($pause)
  126. {
  127.     Write-Host "Press any key to exit..."
  128.     [System.Console]::ReadKey() | Out-Null
  129. }

  130. # Never exits cleanly
  131. exit 1


    • Related Articles

    • Server Setup Ticket Format

      Hello @all   [ ALL TL / PM ]   I'm giving a template for server setup. I'd like to propose that all team-leaders and project-managers create all set-up tickets themselves.  NOTE - Please double-check all project-related details in the README.md file ...
    • Server Deployment

      Click here for Server Deployment
    • view logs in grafana openxcell

      Hello Here, I'll outline every step for viewing the API-Development server's logs. technology is used, such as Java, Node.js, and Next.js. Step 1 : Login GRAFANA : https://grafana.openxcell.dev/login Note : Login with openxcell SSO Step 2 : Go to ...
    • Connecting to development database

      Overview: Database Admin UI URL PHPMyAdmin https://pma.openxcell.dev Adminer https://adminer.openxcell.dev MySQL Databases: For all the application using mysql database https://pma.openxcell.dev serves the PHPMyAdmin Frontend. To access the ...
    • CHANGE GITLAB RUNNER

      Required Details : - server architectures type [ x86, AMD64, ARM64, ARM, s390x, ppc64le ] - super user access [ sudo password ] SSH in server where you want to set git runner. Step 1) #download binary for your system Warning : Select binary as per ...