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?