Bug 2098

Summary: sftp doesn't handle '#' within filenames for transfer
Product: Portable OpenSSH Reporter: Greg Shively <gregory_shively>
Component: sftpAssignee: Assigned to nobody <unassigned-bugs>
Status: CLOSED WORKSFORME    
Severity: normal CC: djm
Priority: P5    
Version: 5.8p2   
Hardware: All   
OS: All   
Attachments:
Description Flags
Allow hash('#') character in filename patch. none

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