PowerShell and AddRawData

Advertisement

rmcclung
Joined:
Posts:
1
Location:
Toronto

PowerShell and AddRawData

try
    {
    # Load WinSCP .NET assembly
    [Reflection.Assembly]::LoadFrom("C:\Program Files\WinSCP\WinSCPnet.dll") | Out-Null 
    # Setup session options
    
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::ftp
    $sessionOptions.HostName = $site
    $sessionOptions.UserName = $user
    $sessionOptions.Password = $password
    $sessionOptions.FTPSecure = "ExplicitSSL"
    $sessionOptions.GiveUpSecurityAndAcceptAnyTlsHostCertificate = $true
    $localpath = $filename
    $remotepath = $path
    
    $session = New-Object WinSCP.Session
    $session.SessionLogPath = '\\ontario\HH_Outbound\zachpay_outbound\Transmission.log'
    
    try
        {
        # Connect
        
        $session.Open($sessionOptions)
 
        # Upload files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
        $check = Test-Path -Path $localpath
            If ($check -eq $false){
                Write-Verbose "File Missing"
                $Exit = 1
                }
            Else {
                $transferResult = $session.PutFiles($localpath, $remotepath, $False, $transferOptions)
                 # Throw on any error
                $transferResult.Check()
 
                # Print results
                foreach ($transfer in $transferResult.Transfers)
                    {
                    Write-Verbose ("Upload of {0} succeeded" -f $transfer.FileName)
                       Write-Output "0"
                    }
                }
        }
    catch [Exception]
        {
        Write-Verbose $_.Exception.Message
        Write-Output "1"
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
I am trying to add raw data to this to turn off UTF
$sessionOptions.DefaultConfiguration = $false
$sessionOptions.AddRawSettings = ("Utf", "0")
but I keep getting the following errors:
Property 'DefaultConfiguration' cannot be found on this object; make sure it exists and is settable.
At C:\Scripts\Production.ps1:41 char:3
+         $sessionOptions.DefaultConfiguration = $false
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException
And the following without the DefaultConfiguration option:
Exception setting "AddRawSettings": "Cannot set the Value property for PSMemberInfo object of type 
"System.Management.Automation.PSMethod"."
At C:\Scripts\Production.ps1:41 char:3
+         $sessionOptions.AddRawSettings = ("Utf", "0")
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting
 
New-Object : Exception calling ".ctor" with "1" argument(s): "Could not find file 
'\\ONTARIO\HH_Outbound\zachpay_outbound\Archive\Logs\TransmissionLog - 08.28.2014.11.28.32 - .log'."
At C:\Scripts\Production.ps1:103 char:10
Any ideas?

Reply with quote

Advertisement

david.white@american-equity.com
Joined:
Posts:
2
Location:
Iowa

Need full code snippet, please

I'm setting the SessionOptions like below.
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "${RemoteHostName}"
    UserName = "${RemoteUserName}"
    Password = "${Password}"
    SshHostKeyFingerprint = "${FingerPrint}"
    Timeout = "00:05:00"
}
How do I add the AddRawSettings parm to this format? Adding, AddRawSettings("SendBuf", "0") fails with message,
At C:\PROGRAM FILES\ASCI\ACTIVEBATCHV12\EXECCOPYFILES\ACTIVEBATC-SFTP_TO_BLACKLI-2423696.PS1:13 char:17
+         AddRawSettings("SendBuf", "0")
+                       ~
Missing '=' operator after key in hash literal.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,277
Location:
Prague, Czechia

Re: Need full code snippet, please

@david.white: As my answer above says. It's a method, so you call it as any other method in PowerShell:
$sessionOptions.AddRawSettings("SendBuf", "0")

Reply with quote

Advertisement

You can post new topics in this forum