Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-SFTPItem failing if Path has en dash #524

Open
artagame opened this issue Apr 17, 2023 · 17 comments
Open

Get-SFTPItem failing if Path has en dash #524

artagame opened this issue Apr 17, 2023 · 17 comments

Comments

@artagame
Copy link

Hi I have a folder from our SFTP server who has en dash in its path and whenever we tried to use the command to download the folder in our local machine it is failing saying that the folder is not existing. Any suggestions or workaround for this?

@artagame
Copy link
Author

@darkoperator please help. thank you!

@MVKozlov
Copy link
Contributor

You may try to play with Session.ConnectionInfo.Encoding setting

$sftp = New-SftpSession .....
$sftp.Session.ConnectionInfo.Encoding = [System.Text.Encoding]::GetEncoding(1252)

with your code page of course

@artagame
Copy link
Author

You may try to play with Session.ConnectionInfo.Encoding setting

$sftp = New-SftpSession .....
$sftp.Session.ConnectionInfo.Encoding = [System.Text.Encoding]::GetEncoding(1252)

with your code page of course

tried this one even changing the encoding but still not working :(

@MVKozlov
Copy link
Contributor

did a test (with standard dash and unicode from U+2012 to U+2015)
no problem with ubuntu (default utf-8)
Try outputting this file through an sftp session using Get-SFTPChildItem to check for the correct encoding.

@darkoperator
Copy link
Owner

╭─ pwsh  ~                                                                                              06:12:52 
╰─❯ Get-SFTPChildItem -SessionId 0 -Path "/tmp"

FullName       : /tmp/this-is-a-test
LastAccessTime : 4/17/2023 6:11:06 AM
LastWriteTime  : 4/17/2023 6:11:39 AM
Length         : 4096
UserId         : 1000

FullName       : /tmp/klippy_uds
LastAccessTime : 4/16/2023 7:38:02 PM
LastWriteTime  : 4/16/2023 7:38:02 PM
Length         : 0
UserId         : 1000

FullName       : /tmp/.ICE-unix
LastAccessTime : 4/15/2023 9:17:04 PM
LastWriteTime  : 4/15/2023 9:17:04 PM
Length         : 4096
UserId         : 0

FullName       : /tmp/.Test-unix
LastAccessTime : 4/15/2023 9:17:04 PM
LastWriteTime  : 4/15/2023 9:17:04 PM
Length         : 4096
UserId         : 0

FullName       : /tmp/printer
LastAccessTime : 4/15/2023 9:24:18 PM
LastWriteTime  : 4/15/2023 9:24:18 PM
Length         : 10
UserId         : 1000

FullName       : /tmp/.font-unix
LastAccessTime : 4/15/2023 9:17:04 PM
LastWriteTime  : 4/15/2023 9:17:04 PM
Length         : 4096
UserId         : 0

FullName       : /tmp/systemd-private-88a2db33291e4d6abfdad0fead8d28b3-systemd-timesyncd.service-16ATfW
LastAccessTime : 4/15/2023 9:17:04 PM
LastWriteTime  : 4/15/2023 9:17:04 PM
Length         : 4096
UserId         : 0

FullName       : /tmp/klipper_host_mcu
LastAccessTime : 4/16/2023 7:38:01 PM
LastWriteTime  : 4/16/2023 7:38:01 PM
Length         : 10
UserId         : 0

FullName       : /tmp/.XIM-unix
LastAccessTime : 4/15/2023 9:17:04 PM
LastWriteTime  : 4/15/2023 9:17:04 PM
Length         : 4096
UserId         : 0

FullName       : /tmp/.X11-unix
LastAccessTime : 4/15/2023 9:17:04 PM
LastWriteTime  : 4/15/2023 9:24:17 PM
Length         : 4096
UserId         : 0

FullName       : /tmp/.X0-lock
LastAccessTime : 4/15/2023 9:24:17 PM
LastWriteTime  : 4/15/2023 9:24:17 PM
Length         : 11
UserId         : 0


╭─ pwsh  ~                                                                                              06:13:25 
╰─❯ Get-SFTPItem -SessionId 0 -Path '/tmp/this-is-a-test' -Destination ./ -Verbose
VERBOSE: Downloading /tmp/this-is-a-test/test.txt
╭─ pwsh  ~                                                                                              06:14:11 
╰─❯ ls .\this-is-a-test\

        Directory: C:\Users\Carlos Perez\this-is-a-test


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a---         4/17/2023   6:14 AM              0   test.txt

How are you running the command so I can replicate.

@artagame
Copy link
Author

artagame commented Apr 18, 2023

@darkoperator thank you so much for responding

` $sftpSession = New-SFTPSession -ComputerName $ctnIP -Credential $pscred -KeyFile $keyFile -OperationTimeout -1 -AcceptKey
Get-SFTPItem -SessionId $sftpSession.SessionId -Path $value -Destination $localTargetDirectory -Force

`

I executing this using PowerShell and the value for Path is a parameter

I am getting this error:
image

and when I tried to list the folders I got this
image

folder name: 20230414 - Spark-ONYX – Dress Rehearsal - ReDrop

@darkoperator
Copy link
Owner

darkoperator commented Apr 18, 2023 via email

@artagame
Copy link
Author

@darkoperator its an en dash

@darkoperator
Copy link
Owner

darkoperator commented Apr 18, 2023 via email

@artagame
Copy link
Author

@darkoperator using WinSCP here is the folder name
image

@MVKozlov
Copy link
Contributor

I think encoding of "en dash" ( U+2013 ?) in $value not correct
for test you may try to list contents with Get-SFtpChildItem and pass result to Get-SFTPItem.
This may work

@artagame
Copy link
Author

I think encoding of "en dash" ( U+2013 ?) in $value not correct for test you may try to list contents with Get-SFtpChildItem and pass result to Get-SFTPItem. This may work

Hi @MVKozlov tried this but it's not working, it's just getting this so it still returns an error
image

@MVKozlov
Copy link
Contributor

I don't like the "-1" in your UserId and Length outputs, it seems like something is wrong with the access or it could be an OS issue.
I still think it's an encoding problem.

Did you tried Get-SFTPChildItem .... | Foreach-Object { Get-SFTPItem .... -Path $_.Fullname }
or your code was different ?

@MikeMM70
Copy link

MikeMM70 commented Apr 18, 2023

That looks like a hyphen to me, not a dash. Have you tried converting the filename to Unicode character values to see what that character really is?

$strng[0..$strng.length] | foreach { [double][char]($_) }

*Edited because I should have started at 0 on the string, not 1

@artagame
Copy link
Author

@MikeMM70 tried it and I got 65533
image

@artagame
Copy link
Author

artagame commented Apr 20, 2023

I don't like the "-1" in your UserId and Length outputs, it seems like something is wrong with the access or it could be an OS issue. I still think it's an encoding problem.

Did you tried Get-SFTPChildItem .... | Foreach-Object { Get-SFTPItem .... -Path $_.Fullname } or your code was different ?
yes I got the full name by using Get-SFTPChildItem

image

@MVKozlov
Copy link
Contributor

There is something really wrong with encoding
65533 - 0xfffd - unicode replacement character
https://www.fileformat.info/info/unicode/char/0fffd/index.htm
that is, it means that the symbol on the server cannot be displayed on the client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants