Guest User

4players Gameserver Backup Download Automation

a guest
May 31st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param (
  2.     $localPath = "C:\temp\ARK_Backup\",
  3.     $remotePath = "/xxxx/ShooterGame/Saved/*"
  4. )
  5.  
  6. try
  7. {
  8.     # Load WinSCP .NET assembly
  9.     Add-Type -Path "C:\temp\WinSCP\WinSCP-5.15.1-Automation\WinSCPnet.dll"
  10.  
  11.     # Setup session options
  12.     $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
  13.         Protocol = [WinSCP.Protocol]::Ftp
  14.         HostName = "saves.4netplayers.de"
  15.         UserName = "xx.xx.xx.xx"
  16.         Password = "passwort"
  17.     }
  18.  
  19.     $session = New-Object WinSCP.Session
  20.  
  21.     try
  22.     {
  23.         # Connect
  24.         $session.Open($sessionOptions)
  25.  
  26.         # Format timestamp
  27.         #$stamp = $(Get-Date -Format "yyyyMMddHHmmss")
  28.         $stamp = $(Get-Date -Format "yyyyMMdd")
  29.  
  30.         # Donwload files
  31.         $transferOptions = New-Object WinSCP.TransferOptions
  32.         $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
  33.  
  34.         $session.add_QueryReceived( {
  35.             Write-Host "Error: $($_.Message)"
  36.             $_.Continue()
  37.         } )
  38.  
  39.         #$transferResult = $session.GetFiles("/552919/ShooterGame/Saved/*", "D:\temp\ARK\*", $False, $transferOptions)
  40.         $transferResult = $session.GetFiles($remotePath,($localPath + $stamp + "\*"), $False, $transferOptions)
  41.        
  42.  
  43.         # Throw on any error
  44.         $transferResult.Check()
  45.  
  46.         # Print results
  47.         foreach ($transfer in $transferResult.Transfers)
  48.         {
  49.             Write-Host "Download of $($transfer.FileName) succeeded"
  50.         }
  51.     }
  52.     finally
  53.     {
  54.         # Disconnect, clean up
  55.         $session.Dispose()
  56.     }
  57.  
  58.     exit 0
  59. }
  60. catch
  61. {
  62.     Write-Host "Error: $($_.Exception.Message)"
  63.     exit 1
  64. }
Add Comment
Please, Sign In to add comment