.NET assembly in PowerShell – GetFiles – append seems not working

Advertisement

marc4provant
Guest

.NET assembly in PowerShell – GetFiles – append seems not working

Greetings,
I'm using the WinSCP assembly quite frequently.

Recently I was trying to retrieve some CSV-files from a remote FTP server and append them in one larger CSV-file for further processing.
But it seems the append does not work (yet)?
Perhaps I'm missing something obvious.

I just downloaded and tried the latest available version: 5.19.6

Basically my script looks like this:
Add-Type -Path ".\WinSCPnet.dll"
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.HostName = "... hostname ..."
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.UserName = " ... username ..."
$sessionOptions.Password = " ... pwd ... "
$sessionOptions.SshHostKeyFingerprint = " ... "
$session = New-Object WinScp.Session
$session.Open($sessionOptions) 
$transferOption = New-Object WinSCP.TransferOptions
$transferOption.preserveTimestamp = $true
$transferOption.TransferMode = [WinSCP.TransferMode]::Ascii
$transferOption.OverwriteMode = [WinSCP.OverwriteMode]::Overwrite
$transferResult = $session.GetFiles(" ... remotefile#1 ", "c:\temp\localfile.csv" ,$false ,$transferOption );
 
$transferOption.OverwriteMode = [WinSCP.OverwriteMode]::Append
$transferResult = $session.GetFiles(" ... remotefile#2 ", "c:\temp\localfile.csv" ,$false ,$transferOption );

Reply with quote

Advertisement

Guest

Re: .NET assembly in PowerShell – GetFiles – append seems not working

Am I correct that the script I provided is correct?
And that the two files should be appended into one?
Which is not happening at the moment.

Reply with quote

martin
Site Admin
martin avatar

Re: .NET assembly in PowerShell – GetFiles – append seems not working

Yes it's "correct". But appending is NOT supported with FTP.

Reply with quote

Advertisement

You can post new topics in this forum