[patch] sftp-server writes uploads to a temporary file then renames them when finished

Damien Miller djm at mindrot.org
Sun Jun 6 10:43:27 EST 2004


gabriel russell wrote:
> Well, my boss asked me to write this patch and I figured I'd share it in 
> case someone else wanted to use it. It's clearly not for incorporating 
> into the main tree.

This isn't going to be reliable because the filexfer protocol (sftp)
doesn't really have a notion of an "upload" - it sees a open, a bunch
of writes and a close. While this will usually represent an upload, it
could also be modifications to a different file. You could make this
a bit more robust by only activating it for creations or truncations.

> It would need to be configurable, and since there is 
> no configuration system for sftp, it can't easily be.

When I have made modifications to sftp-server that have required passing
in configuration options, I just pass them on the commandline and use
a wrapper script in sshd_config's SubSystem directive (because
sshd_config doesn't allow the passing of commandline options to
subsystems.)

> I could make it look for an environment variable for the tmp-name-suffix 
> and use it's existence to indicate weather or not to use tmp files.

You should just use mkstemp to give you a fd to a temporary file, rather
than making something that could be clobbered by multiple simultaneous
uploads.

-d




More information about the openssh-unix-dev mailing list