Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

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: 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.
Travisty54

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