PowerShell Length Calculation Incorrect Using WinSCP assembly

Advertisement

Travisty54
Joined:
Posts:
1
Location:
Nashville

PowerShell Length Calculation Incorrect Using WinSCP assembly

I ran into an interesting problem that I'm not sure if it's a bug or if I'm just doing something incorrect.

I have a need to pull a file via sFTP and have decided to script it using powershell with the WinSCP dll so I can have the best of both.

I start off by enumerating through the remote files.
# Begin transfer and logging of file.
$FileNames = $session.EnumerateRemoteFiles($FTPPath,"",[WinSCP.EnumerationOptions]::None)
$Files = $FileNames.FullName

Then I foreach through the files:
      ForEach ($File in $Files) 
         {   
            # Transfer File and log both size and transfer time.
            $FileLength = $File.Length 
            $FileLength
}

Unfortunately, the value I end up with for the length of the source file is double what the length actually is. I'm getting a value of 52KB while the file is actually 25KB and change.

My goal is to compare a file before and after transfer to validate that the file transferred properly. Can anyone shed light on what I'm doing wrong with the length or suggest a better way to compare pre and post transfer files?

Super appreciated

Reply with quote E-mail

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
29,095
Location:
Prague, Czechia

Re: PowerShell Length Calculation Incorrect Using WinSCP assembly

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Advertisement

You can post new topics in this forum