This is the relevant part of the script which deals with the sync:
$global:sessionOptions = New-Object WinSCP.SessionOptions $global:sessionOptions.Protocol = [WinSCP.Protocol]::Sftp $global:sessionOptions.HostName = $customservername $global:sessionOptions.UserName = $customsftpuser $global:sessionOptions.SshPrivateKeyPath = $ppkfile $global:sessionOptions.SshHostKeyFingerprint = $rsakey $global:session = New-Object WinSCP.Session $global:session.Open($global:sessionOptions) $global:transferOptions = New-Object WinSCP.TransferOptions $global:transferOptions.TransferMode = [WinSCP.TransferMode]::Automatic $synchronizationResult = $global:session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Local,$localdirectorypath, $remotepath, $False, $False, [WinSCP.SynchronizationCriteria]::Time, $global:transferOptions) bla bla bla
It is working perfectly for 99.99% of the files it deals it, but recently the user which is monitoring this script on the server told me there is a problem with line breaks with one of the file types.
My script is set to use automatic file type handling and it is working for known file types, like pdf, xml and txt files. The problem is that there is a custom file type *.LBL which in fact is a text file that is generated on the remote Linux which is being downloaded in binary mode to the local Windows server. I suppose the automatic transfer mode is considering this file type as unknown and hence downloading them in binary mode.
In the Windows server, there is a hardware attached to the machine which reads these *.LBL files and it expects for CRLF line breaks, not LF only. So I can't change the file extension on the source and I don't believe it is a good approach to deal with *.LBL files separately. The required solution is to keep the script almost as is, applying the least changes as possible, but still making it able to download these *.LBL files as ASCII so the line breaks are properly converted during the synchronization.
I'm trying to avoid making significant modifications on the way the current script works because it is used to sync many file types and it is working perfectly to the other files. So I'm wondering if it is possible to change what file extensions are considered as ASCII files in the automatic transfer mode, but need to change that setting through script.
In other words, I'm looking for help on changing the settings through script, so the *.LBL file extension is considered as "text" and hence it would be downloaded in ASCII mode (when using automatic transfer mode like in the code above).
PS: the server doesn't have Winscp installed.
Any help is very appreciated. This issue is kind of urgent now.