Bug 2098 - sftp doesn't handle '#' within filenames for transfer
Summary: sftp doesn't handle '#' within filenames for transfer
Status: CLOSED WORKSFORME
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sftp (show other bugs)
Version: 5.8p2
Hardware: All All
: P5 normal
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-08 01:34 AEST by Greg Shively
Modified: 2015-08-11 23:05 AEST (History)
1 user (show)

See Also:


Attachments
Allow hash('#') character in filename patch. (460 bytes, patch)
2013-05-08 01:34 AEST, Greg Shively
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Shively 2013-05-08 01:34:04 AEST
Created attachment 2255 [details]
Allow hash('#') character in filename patch.

Not sure if this is by design, but ran across some files being transferred using sftp v4.5. When upgraded to v5.8 the filename is truncated at the '#' in the filename.

If this is not by design, added a quick patch that seems to resolve.
Comment 1 Damien Miller 2013-05-08 09:25:15 AEST
'#' is intentionally used to indicate the start of a comment.

Like other special characters, it should be quoted, e.g.

get "a#b"
Comment 2 Greg Shively 2013-05-09 02:06:52 AEST
(In reply to comment #1)
> '#' is intentionally used to indicate the start of a comment.
> 
> Like other special characters, it should be quoted, e.g.
> 
> get "a#b"

Thanks. Will get our users to modify their code. Was not sure what the decision would be, and I shouldn't have been so terse in the ticket. But 2 things that you might want to consider.

1. Older versions 4.5, worked differently:
      $ ssh -V
      OpenSSH_4.5p1, OpenSSL 0.9.8d 28 Sep 2006
      $ sftp `hostname`:/tmp/a#a
      Fetching /tmp/a#a to a#a
   But newer versions:
      $ ssh -V
      OpenSSH_5.8p1, OpenSSL 0.9.8a 11 Oct 2005
      $ sftp `hostname`:/tmp/b#b
      File "/tmp/b" not found.

2. I was also under the impression that the '#' started a comment, but after seeing how from the shell we had to quote the '#', it doesn't look like all of the shell's parsers that I tested worked that way. It looks like the '#' only starts a comment at the beginning of a token:
      $ touch #a
      touch: missing file operand
      Try `touch --help' for more information.
      $ touch a#a
      $ ls a#a
      a#a
      

Thanks again for any additional thought on this.
Comment 3 Damien Miller 2015-08-11 23:05:05 AEST
Set all RESOLVED bugs to CLOSED with release of OpenSSH 7.1