Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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

Yes it's "correct". But appending is NOT supported with FTP.
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.
marc4provant

.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 );