Topic "Reconnect and Resume"

Author Message
[View user's profile]

Joined: 2012-10-04
Posts: 4
Location: Florida
I am using Powershell with the .NET assembly to obtain a 7G file on a daily basis. There are occasional times where the download is interrupted for various reasons of which the supplier has not been able to identify. I have used a "for" loop to execute the transfer multiple times after a failure. However, it seems the transfer always starts the from the beginning of the file on each iteration. This is very time consuming especially if the the transfer aborts 45 minutes into the download and starts from the beginning again. I do know the server supports resuming a download.

Am I missing something in the session options to enable an automatic reconnect and resuming a download where it left off?
Function Get-SupplierFtpFile
      [Parameter(Position=0, Mandatory=$True)]
      [Parameter(Position=1, Mandatory=$True)]
      [Parameter(Position=4, Mandatory=$false)]
      [int]$Iterations = 36,
      [Parameter(Position=5, Mandatory=$false)]
      [int]$WaitSeconds = 300

      [Void][System.Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\WinSCP\WinSCP.dll")
      $FileName = [System.IO.Path]::GetFileName($RemotePath)
       # Setup session options
       $sessionOptions = New-Object WinSCP.SessionOptions
       $sessionOptions.Protocol = [WinSCP.Protocol]::Ftp
      $sessionOptions.FtpMode = [WinSCP.FtpMode]::Passive
       $sessionOptions.HostName = ""
       $sessionOptions.UserName = "Username"
       $sessionOptions.Password = "pa$$word"
      $sessionOptions.PortNumber = 990
      $sessionOptions.FtpSecure = [WinSCP.FtpSecure]::Implicit
       $sessionOptions.SslHostCertificateFingerprint = "99:98:97:96:19:2f:dd:cc:aa:ff:89:78:77:66:76:75:74:73:72:71"
        # Connect
       $session = New-Object WinSCP.Session
      $session.SessionLogPath = "D:\Logs\GetFTP\$(Get-Date -Format "yyyyMMddHHmm").FTPlog.txt"

         For([int]$x = 1;$x -le $Iterations;$x += 1)
            Write-EventLog -LogName ScriptEvents -Source PowerShellITG `
               -Message "Supplier refresh: Download started." `
               -EventId 1001 -EntryType Information

               Write-Warning $_.Exception.Message
               Write-EventLog -LogName ScriptEvents -Source PowerShellITG `
                  -Message "Supplier refresh: Download aborted $x times. Retry in 5 minutes." `
                  -EventId 1002 -EntryType Warning
            Start-Sleep -Seconds $WaitSeconds

         If($x -ge $Iterations)
            Throw "Excessive time waiting for remote file access."
         Get-Item $localPath -ErrorVariable ERR -ErrorAction SilentlyContinue | Out-Null
            Throw  $ERR.Message
         Return $localPath
          Throw $_.Exception
        # Disconnect, clean up
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26890
Location: Prague, Czechia
The WinSCP .NET assembly does not support resuming yet.
Martin Prikryl

You can post new topics in this forum


What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License