SFTP - can't transfer files with spaces in the filename [hetzner Storage Box]

Support for Android version of Total Commander

Moderators: Hacker, petermad, Stefan2, white

Post Reply
EATgahh3
Junior Member
Junior Member
Posts: 4
Joined: 2025-05-06, 16:58 UTC

SFTP - can't transfer files with spaces in the filename [hetzner Storage Box]

Post by *EATgahh3 »

Hello,
I'm using the SFTP plugin, but I can't transfer files with spaces in the filename, UL and DL affected.
If I remove the space chars in filename, the file can be transferred ok.
My sftp storage supports filenames with spaces.

Code: Select all

Error reading the file ! 
///SFTP/..../20250505 Monatlicher Kontoauszug.pdf
tested on Android, multiple devices, SFTP type: hetzner Storage Boxes


Is this a known issue ?

Thanks very much.
Last edited by EATgahh3 on 2025-05-08, 19:38 UTC, edited 1 time in total.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50532
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: SFTP - can't transfer files with spaces in the filename

Post by *ghisler(Author) »

No, the problem isn't known. It must be a bug in their SFTP server. This forum is running on Hetzner, and I can upload and download files with spaces in the name just fine.
Please try enabling SCP for transfers, it sends names in a different way.
Author of Total Commander
https://www.ghisler.com
EATgahh3
Junior Member
Junior Member
Posts: 4
Joined: 2025-05-06, 16:58 UTC

Re: SFTP - can't transfer files with spaces in the filename

Post by *EATgahh3 »

Thanks very much for the feedback.
ssh and scp access is enabled in my storage box.

I found the log function in TC, here it is:

Code: Select all

2025-05-07 20:14:57.724 HOST:SFTP:get dir: /
2025-05-07 20:15:04.649 SFTP:refresh list
2025-05-07 20:15:04.815 HOST:SFTP:get dir: /
2025-05-07 20:15:10.940 HOST:SFTP:get dir: /haa/x/
2025-05-07 20:15:11.001 SFTP:=====================
2025-05-07 20:15:11.060 SFTP:IP[0]: 2a01:4f8:xxxxxxx
2025-05-07 20:15:11.061 SFTP:IP[1]: 49.12.xxxxx
2025-05-07 20:15:11.062 SFTP:Connecting...: 49.12.xxxxx
2025-05-07 20:15:11.168 SFTP:Algorithm: RSA, Fingerprint: 3d:7b:6f:99:5f:68:53:21:73:15:f9:2e:6b:3a:9f:e3
2025-05-07 20:15:11.169 SFTP:Negotiated algorithms: [ kex=diffie-hellman-group-exchange-sha256; sig=rsa-sha2-512; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha2-256; s2cMAC=hmac-sha2-256; c2sComp=none; s2cComp=none;  ]
2025-05-07 20:15:11.170 SFTP:Logging in...
2025-05-07 20:15:11.226 SFTP:Password: ********
2025-05-07 20:15:11.228 SFTP:SFTP start...
2025-05-07 20:15:11.283 SFTP:Connect OK!
2025-05-07 20:15:11.284 SFTP:SFTP LIST /x/
2025-05-07 20:15:11.360 SFTP:CONNECT haa
2025-05-07 20:15:15.821 tc:Copy 1 files:///SFTP/haa/x/->/storage/emulated/0/Download/
2025-05-07 20:15:17.252 SFTP:GET /x/20250505 Monatlicher Kontoauszug.pdf
2025-05-07 20:15:17.312 SFTP:GET error: SCPRemoteException: Remote SCP command returned error: '/x/20250505: No such file or directory
Looks like a quoting issue ?
I found a workaround, when I disable "SCP" option in the SFTP plugin on Android then it works:

Code: Select all

2025-05-07 20:12:15.062 HOST:SFTP:checkConnectionAlive: 1
2025-05-07 20:12:15.063 HOST:SFTP:get dir: /haa/x/
2025-05-07 20:12:15.133 SFTP:=====================
2025-05-07 20:12:15.191 SFTP:IP[0]: 2a01:4f8:xxxx
2025-05-07 20:12:15.192 SFTP:IP[1]: 49.12.xxxxx
2025-05-07 20:12:15.193 SFTP:Connecting...: 49.12.xxxx
2025-05-07 20:12:15.312 SFTP:Algorithm: RSA, Fingerprint: 3d:7b:6f:99:5f:68:53:21:73:15:f9:2e:6b:3a:9f:e3
2025-05-07 20:12:15.315 SFTP:Negotiated algorithms: [ kex=diffie-hellman-group-exchange-sha256; sig=rsa-sha2-512; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha2-256; s2cMAC=hmac-sha2-256; c2sComp=none; s2cComp=none;  ]
2025-05-07 20:12:15.316 SFTP:Logging in...
2025-05-07 20:12:15.368 SFTP:Password: ********
2025-05-07 20:12:15.369 SFTP:SFTP start...
2025-05-07 20:12:15.422 SFTP:Connect OK!
2025-05-07 20:12:15.423 SFTP:SFTP LIST /x/
2025-05-07 20:12:15.490 SFTP:CONNECT haa
2025-05-07 20:12:19.615 tc:Copy 1 files:///SFTP/haa/x/->/storage/emulated/0/Download/
2025-05-07 20:12:21.043 SFTP:GET /x/20250505 Monatlicher Kontoauszug.pdf
2025-05-07 20:12:34.092 HOST:SFTP:disconnect all: haa
2025-05-07 20:12:34.114 SFTP:OFFLINE! xxxxxxxxxxxx.your-storagebox.de
I don't understand this. Does this makes sense to you ?

BTW: hetzner offers 2 ways to connect: port 22 (which I use) and port 23 (which did here not work for me), Maybe here is a difference ?
https://docs.hetzner.com/storage/storage-box/access/access-overview
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50532
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: SFTP - can't transfer files with spaces in the filename

Post by *ghisler(Author) »

It doesn't make sense, it works just fine with ghisler.ch. :-(
Author of Total Commander
https://www.ghisler.com
EATgahh3
Junior Member
Junior Member
Posts: 4
Joined: 2025-05-06, 16:58 UTC

Re: SFTP - can't transfer files with spaces in the filename

Post by *EATgahh3 »

Except the error I can't see a relevant delta in my two provided log files ?
What does the "SCP" option in the SFTP plugin do ? Default is on ?

Checking the hetzer storage box from my linux machine, scp vs sftp: both works fine.

Code: Select all

# x86_64 GNU/Linux 6.13

$ scp haa:x/20250505\ Monatlicher\ Kontoauszug.pdf .
20250505 Monatlicher Kontoauszug.pdf                    100%   17KB 483.1KB/s   00:00    


$ sftp haa
Connected to haa.
sftp> get x/20250505\ Monatlicher\ Kontoauszug.pdf
Fetching /x/20250505 Monatlicher Kontoauszug.pdf to 20250505 Monatlicher Kontoauszug.pdf
20250505 Monatlicher Kontoauszug.pdf                    100%   17KB 479.9KB/s   00:00    
sftp> 
Of course, filenames must be escapes properly, either by a \ for the spaces, or within double quotes " or single quotes '
And this is what I conclude from post #3 error log : escaping seems not to be done:

Code: Select all

SCPRemoteException: Remote SCP command returned error: '/x/20250505: No such file or directory
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50532
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: SFTP - can't transfer files with spaces in the filename

Post by *ghisler(Author) »

The SCP option makes the plugin download the file via scp command instead of via sftp file transfer. Normally scp is faster.

According to the sshj library source file ScpCommandLine.java, spaces are escaped by a backslash followed by a space.

Code: Select all

public enum EscapeMode {
        NoEscape,
        Space {
            @Override
            String escapedPath(String path) {
                return path.replace(" ", "\\ ");
            }
        },
...
I don't understand why this works with all other ssh servers but not with Hetzner's.
Author of Total Commander
https://www.ghisler.com
EATgahh3
Junior Member
Junior Member
Posts: 4
Joined: 2025-05-06, 16:58 UTC

Re: SFTP - can't transfer files with spaces in the filename

Post by *EATgahh3 »

I'm no java expert, but EscapeMode provides 4 modes: NoEscape, Space, DoubleQuote, SingleQuote
But in this java file, no one is choosen /selected ?
Where is decided, which mode is used ?
Or is it extern decided and the sub routine is called with the right mode ?

And you are right: I tested TC Android SFTP versus a fresh VPS server just booted with an Arch Linux iso - no issue here.
Thanks for you testing + hint, that there is no issue with your server.

So there is a rare bug in the Hetzern's storage box product ?
Or does the java code does not detect the correct escape mode with active SCP mode ?

Further test, Android SFTP vs hetzer storage box:
filename with DoubleQuote : not possible for me. Android does not allow filename with DoubleQuote ?
filename with SingleQuote : download direction working, upload not !
Strange...
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50532
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: SFTP - can't transfer files with spaces in the filename [hetzner Storage Box]

Post by *ghisler(Author) »

I just found out that my new plugin host is actually a Hetzner storage box, and I can indeed reproduce the issue.

I have further investigated the code: In SCPDownloadClient.java, the sshj implementation uses ScpCommandLine.EscapeMode.NoEscape, while TC uses ScpCommandLine.EscapeMode.SingleQuote, which means that it puts the parameter in single quotes and doesn't escape spaces. The actual command sent is:
scp -t -r -p '/public_html/test/a a.txt'

For test purposes, I have changed to ScpCommandLine.EscapeMode.Space, which sends the following command:
scp -t -r -p /public_html/test/a\ a.txt

However, this also returns an error.
Same problem with downloading, the command lines
scp -f -q -p -r '/public_html/test/a a.txt'
and
scp -f -q -p -r /public_html/test/a\ a.txt
both return an error.

A successful command line for uploading looks like this (no spaces):
scp -t -r -p /public_html/test/b.txt
Author of Total Commander
https://www.ghisler.com
Post Reply