Topic "Powershell and AddRawData"

Author Message
rmcclung
[View user's profile]

Joined: 2014-08-28
Posts: 1
Location: Toronto
Code:

   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

Code:

$sessionOptions.DefaultConfiguration = $false
$sessionOptions.AddRawSettings = ("Utf", "0")


but I keep getting the following errors:

Code:

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:
Code:

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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Code:
$sessionOptions.AddRawSettings = ("Utf", "0")

The AddRawSettings is a method, so there should be no equal sign. You should do:
Code:
$sessionOptions.AddRawSettings("Utf", "0")
Advertisements

You can post new topics in this forum






Search Site

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!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License