scp doesn't report correct filenames with spaces in verbose mode

Bug #89945 reported by psl on 2007-03-05
Affects Status Importance Assigned to Milestone
openssh (Ubuntu)
Colin Watson

Bug Description

Binary package hint: openssh-client

Ubuntu 6.06.1, i386

scp doesn't report crrect action when handling files with spaces in filename. An example:

$ touch test\ file
$ touch "file test"
$ mkdir test_dir

$ scp -v file\ test test\ file test_dir
Executing: cp file test test_dir
Executing: cp test file test_dir

Compare with cp command that reports filenames correctly:

$ cp -v file\ test test\ file test_dir
`file test' -> `test_dir/file test'
`test file' -> `test_dir/test file'

$ ssh -V
OpenSSH_4.2p1 Debian-7ubuntu3.1, OpenSSL 0.9.8a 11 Oct 2005

In the past, scp was unable to handle filenames with spaces; it is fixed now, I comply about reporting in -v mode only.

Nicolas Valcarcel (nvalcarcel) wrote :

I'm attaching the patch of this bug fur revision.

Nicolas Valcarcel (nvalcarcel) wrote :

Attaching corresponding debdiff

Changed in openssh:
status: New → Confirmed
Daniel Holbach (dholbach) wrote :

Colin: could you please take a look at it?

Colin Watson (cjwatson) wrote :

Should use strnvis instead, I suspect.

Colin Watson (cjwatson) wrote :

Hmm, strnvis isn't quite right. I guess this unreliable quoting (consider what happens if the filename contains a single quote!) is OK for something that is just for human consumption, though I'd still like something that actually corresponds to real shell quoting in future. I'll apply a variant of this for the meantime.

By the way, please don't change the Maintainer field when it already contains an address

Changed in openssh:
assignee: nobody → kamion
status: Confirmed → Fix Committed
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package openssh - 1:4.7p1-8ubuntu1

openssh (1:4.7p1-8ubuntu1) hardy; urgency=low

  * Resynchronise with Debian. Remaining changes:
    - Add support for registering ConsoleKit sessions on login.

openssh (1:4.7p1-8) unstable; urgency=high

  * Fill in CVE identifier for security vulnerability fixed in 1:4.7p1-5.
  * Rename KeepAlive to TCPKeepAlive in sshd_config, cleaning up from old
    configurations (LP: #211400).
  * Tweak scp's reporting of filenames in verbose mode to be a bit less
    confusing with spaces (thanks, Nicolas Valcárcel; LP: #89945).
  * Backport from 4.9p1:
    - Ignore ~/.ssh/rc if a sshd_config ForceCommand is specified (see
    - Add no-user-rc authorized_keys option to disable execution of
  * Backport from Simon Wilkinson's GSSAPI key exchange patch for 5.0p1:
    - Add code to actually implement GSSAPIStrictAcceptorCheck, which had
      somehow been omitted from a previous version of this patch (closes:

 -- Colin Watson <email address hidden> Sun, 06 Apr 2008 12:44:11 +0100

Changed in openssh:
status: Fix Committed → Fix Released
Tomas M. (el-dragon) wrote :

ok, this is not fixed at all, this is what i get when trying to scp a file with an escaped character
tomas@emmet:~$ touch test\ file
tomas@emmet:~$ logout
Connection to emmet closed.
tomas@lappy:~$ scp tomas@emmet:test\ file ./
scp: test: No such file or directory
scp: file: No such file or directory
tomas@lappy:~$ ssh -V
OpenSSH_4.7p1 Debian-8ubuntu1.2, OpenSSL 0.9.8g 19 Oct 2007

is this the same bug im experiencing?

psl (slansky) wrote :

Ubuntu 8.04, i386.
I can confirm that I can repeat the issue as demonstrated by eldragon. Problem is not fixed. I cannot copy (scp) file with space in filename from one machine to other.

Björn Torkelsson (torkel) wrote :

Use tripple \ for escaping the space. I.e

scp testmachine:File\\\ with\\\ spaces ./

Björn Torkelsson (torkel) wrote :

or use quotes and single \ around the filename, i.e:

scp testmachine:"File\ with\ spaces" ./

Tomas M. (el-dragon) wrote :

could you care explain why is it this way?

Björn Torkelsson (torkel) wrote :

If you run scp with the '-v' (verbose) you can see what command is actually run. It should be in the first line of output.

Without using any \ or " (or ') the filename are treated by the local shell as 3 arguments to scp instead of one; the filename.

In the first case the \ are expanded by the local shell and the result are passed to scp. I.e \\ becames a \ and '\ ' becames ' ', so the string that are passed to scp is actually 'testmachine:File\ with\ spaces', which are then expanded on the remote side, using the same rules.

In the second case the \ are not expanded by the local shell because of the ". The string (including \) are thus expanded on the remote side.

There is actually a third version you can use (at least for the moment):

scp testmachine:"'File with spaces'", i.e using both single and double quotes. The first pair is removed by the local shell and the second pair on the remote side.

Matt LaPaglia (mlapaglia) wrote :

I'm still experiencing this bug.

Tomas M. (el-dragon) wrote :

Matt, as was stated 2 posts above, its the correct behavior to have to double quote or add 3 backslashes.

Colin Watson (cjwatson) wrote :

All you guys are reporting a completely different bug. The original report was specifically about the output under -v, not about the need to escape filenames inconveniently for scp.

While scp's behaviour is inconvenient, it is rather unlikely to change since scp's interface is necessarily frozen for compatibility purposes. The future is sftp, which has a proper protocol.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers