darkoperator / Posh-SSH

PowerShell Module for automating tasks on remote systems using SSH
BSD 3-Clause "New" or "Revised" License
982 stars 227 forks source link

Get-SFTPChildItem does not list file if exact filename specified #598

Open SCP002 opened 1 week ago

SCP002 commented 1 week ago

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.

darkoperator commented 4 days ago

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

SCP002 commented 2 days ago

Thanks for your reply. Understood, it works as intended. 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'

Anyway you can close this issue as completed :)