TransferSupport.State set to "On", but exits upon error

Advertisement

mcarner5
Guest

TransferSupport.State set to "On", but exits upon error

I have the TransferSupport.State in TransferOptions set to "On" yet if there is an issue, the script exits and I see this error:

Upload of FILENAME HERE failed: WinSCP.SessionRemoteException: Error transferring file 'FILENAME HERE'.
Copying files to remote side failed.
Unexpected error encountered. Please retry.
Permissions of  kept with their defaults
Timestamp of  kept with its default (current time)
Error: Exception calling "Check" with "0" argument(s): "Error transferring file 'FILENAME HERE'.
Copying files to remote side failed.
Unexpected error encountered. Please retry."

Am I improperly applying the TransferSupport state? Here is the script I am using:

# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"

# Session.FileTransferred event handler
 
function FileTransferred
{
    param($e)
 
    if ($e.Error -eq $Null)
    {
        Write-Host "Upload of $($e.FileName) succeeded"
    }
    else
    {
        Write-Host "Upload of $($e.FileName) failed: $($e.Error)"
    }
 
    if ($e.Chmod -ne $Null)
    {
        if ($e.Chmod.Error -eq $Null)
        {
            Write-Host "Permissions of $($e.Chmod.FileName) set to $($e.Chmod.FilePermissions)"
        }
        else
        {
            Write-Host "Setting permissions of $($e.Chmod.FileName) failed: $($e.Chmod.Error)"
        }
 
    }
    else
    {
        Write-Host "Permissions of $($e.Destination) kept with their defaults"
    }
 
    if ($e.Touch -ne $Null)
    {
        if ($e.Touch.Error -eq $Null)
        {
            Write-Host "Timestamp of $($e.Touch.FileName) set to $($e.Touch.LastWriteTime)"
        }
        else
        {
            Write-Host "Setting timestamp of $($e.Touch.FileName) failed: $($e.Touch.Error)"
        }
 
    }
    else
    {
        # This should never happen during "local to remote" synchronization
        Write-Host "Timestamp of $($e.Destination) kept with its default (current time)"
    }
}

function FileTransferProgress
{
    param($e)

    Write-Progress `
        -Id 1 -Activity $e.FileName -Status ("{0:P0} complete:" -f $e.FileProgress) `
        -PercentComplete ($e.FileProgress * 100)
}


try
{
    # Set up session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        "sessionOptions here" = ""
    }
 
    $session = New-Object WinSCP.Session
    try
    {
        # Will continuously report progress of synchronization
        $session.add_FileTransferred( { FileTransferred($_) } )

        # Will continuously report progress of transfer
        $session.add_FileTransferProgress( { FileTransferProgress($_) } )
 
        # Connect
        $session.Open($sessionOptions)

        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::On
 
        # Synchronize files
        $synchronizationResult = $session.SynchronizeDirectories(
            [WinSCP.SynchronizationMode]::Remote,    #Remote is synced to match local
            "LOCAL", #Local repository
            "REMOTE",           #Remote repository
            $True,                                   #Delete remove files not in local repository  
            $False,                                  #Do not sync in mirror mode
            [WinSCP.SynchronizationCriteria]::Time,  #Sync based on timestamp
            $transferOptions
            )
 
        # Throw on any error
        $synchronizationResult.Check()
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

Reply with quote

Advertisement

mcarner
Guest

I may be understanding this wrong. Sounds like there is no support for this functionality in the .NET version.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,392
Location:
Prague, Czechia

Re: TransferSupport.State set to "On", but exits upon error

The "Unexpected error encountered. Please retry" most probably comes from the server. I cannot know what it means. Why do you think it has anything to do with TransferOptions.ResumeSupport?

Can you upload the file anyhow? Using WinSCP GUI? Using any other client?

Reply with quote

Advertisement

You can post new topics in this forum