Posh-SSH icon indicating copy to clipboard operation
Posh-SSH copied to clipboard

Get-SFTPChildItem does not list file if exact filename specified

Open SCP002 opened this issue 1 year ago • 2 comments

In v3.2.4, Get-SFTPChildItem no longer has -Name parameter and seems like we are supposed to specify file name in -Parh parameter. However, if you run, for example:

Get-SFTPChildItem -SessionId $sess.SessionId -Path '/home/vlad/.xteve/backup/xteve_auto_backup_20241012_0405.zip'

It will respond with:

Write-Error: Error listing items in /home/vlad/.xteve/backup/xteve_auto_backup_20241012_0405.zip: Exception calling "ListDirectory"
with "1" argument(s): "No such file"

Such file definitely exist and in v3.2.3, if you pass file name with -Name parameter, it returns info about that file.

Note: If you add asterisk in the end of the file name like that:

Get-SFTPChildItem -SessionId $sess.SessionId -Path '/home/vlad/.xteve/backup/xteve_auto_backup_20241012_0405.zip*'

everything will work, but it's inconvenient.

SCP002 avatar Oct 18 '24 10:10 SCP002

as designs, the method for a session used is listdirectory() where the path to list all files is used. The call does not take a path to a file

darkoperator avatar Oct 21 '24 21:10 darkoperator

Thanks for your reply. Maybe we could have -Name parameter back to be able to to get info about specific file, so we dont have to use:

Get-SFTPChildItem -SessionId $sess.SessionId -Path '/path/to/dir' | Where-Object -Property 'Name' -Like 'the-name-i-want'

P.S: If -Name no longer works, but it's visible in Man Get-SFTPChilditem, I think this flag should be removed from manual or else it's confusing. Or, even better, make it work.

SCP002 avatar Oct 23 '24 07:10 SCP002