Get the Size of a File on SFTP Server using Posh-SSH

1.4k Views Asked by At

I have a posh-ssh setup that seems to be working pretty well. I'm looking to get the size of a file.

https://github.com/darkoperator/Posh-SSH/blob/master/docs/Get-SFTPContent.md

I feel like I should be able to do something like Get-SFTPContent.length -byte or something and return JUST the length but I can't find the documentation on exactly how to do this.

The challenge is I don't want to return the whole 600mb file as a bytearray. That would be bad.

1

There are 1 best solutions below

0
On BEST ANSWER

You can run

Get-SFTPChildItem -SessionId <id> | select FullName, Length

to get a list of file names and sizes in your current directory.

Or if you prefer the output shown in kilobytes:

Get-SFTPChildItem -SessionId <id> | select FullName, @{N='Size (kB)';E={$_.Length/1kb}}