darkoperator / darkoperator/Posh-SSH

Get-SftpItem gives an error when trying to get a file that contains illegal characters:

Open
#533 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
1.1k
Forks
222
PR merge metrics
No merged PRs in 30d

Description

Dear
I need to download from ericsson telecom modules: but the files on ftp server includes illegal character, help me to obviate the problem or teach me how to use move-sftpitem to rename files on the server and then download it.
image
I will be thankful if you help me.

$Server = "172.18..."
$RemoteDirectory = "/c/pm_data"
$LocalDirectory = "C:\eric"
$User = " ... "
$PWord = ConvertTo-SecureString -String " ... " -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PWord
$Session = New-SftpSession -ComputerName $Server -Credential $Credential
$Files = Get-SftpChildItem -SessionId $Session.SessionId -Path $RemoteDirectory -Recurse |
Where-Object { $.FullName -like '*.gz' } |
Select-Object -Property @{Name="NewFullName"; Expression={$
.FullName -replace ":" , "_"}}

Download each file

$Files | ForEach-Object {

$RemoteFilePath = $_.NewFullName


# Download the file
move-SftpItem -SessionId $Session.SessionId -Destination c:\eric -Path $RemoteFilePath

}

Close the SFTP session

Remove-SftpSession -SessionId $Session.SessionId

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Get-SftpChildItem and move-SftpItem commands shown in the issue, then inspect the related transfer entry points to reproduce the failure with the remote filename containing illegal characters. No file or test is named; done means establishing whether the path is transformed incorrectly and adding a verified behavior or a documented workaround for downloading or renaming that file.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.