Skip to content

Filename character encoding issue #627

@NoCookiesForYou1

Description

@NoCookiesForYou1

I’m having filename encoding issues when listing files from an SFTP server that use a non-UTF-8 encoding (Nordic letters äöå get replaced with �).

I attempted this workaround:

$SFTPSession = New-SFTPSession -ComputerName x.x.x.x -Port 22 -Credential $Credentials -Verbose
$SFTPSession.Session.ConnectionInfo.Encoding = [System.Text.Encoding]::GetEncoding("ISO-8859-1")
Get-SFTPChildItem -SessionId $SFTPSession.SessionId -Recurse -File

Setting Session.ConnectionInfo.Encoding after connect did not help.
Is there a supported way to set the SSH.NET ConnectionInfo.Encoding before the session connects (e.g., a parameter to New-SFTPSession)?

If I create the SSH.NET ConnectionInfo with Encoding set before connecting, filenames show up correctly.

example

Import-Module Posh-SSH

$enc  = [System.Text.Encoding]::GetEncoding("ISO-8859-1")
$auth = New-Object Renci.SshNet.PasswordAuthenticationMethod($user, $pass)
$conn = New-Object Renci.SshNet.ConnectionInfo("x.x.x.x", 22, $user, $auth)
$conn.Encoding = $enc

$sftp = New-Object Renci.SshNet.SftpClient($conn)
$sftp.Connect()

$sftp.ListDirectory("/") | Select-Object Name, FullName
$sftp.Disconnect()
$sftp.Dispose()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions