Hi,
Enclosed is a small patch that lifts the constraint on uploading only
regular files in sftp(1). It's useful to me in dump(8)ing to a remote
ChrootDirectory'd, ForceCommand sftp-internal server so that I needn't
put dd(1) or something in the jail. This way, I can have an empty jail
for backups and not have the overhead of a dumpfile (which I can't
afford, space-wise).
% echo "put /dev/stdin remoteFile" >test.bat
% dump -0f - /usr/vhosts | sftp -b test.bat [email protected]
Where the backup user is matched with something like
Match user backup
ChrootDirectory /chroot
ForceCommand internal-sftp
The regular solution, something like
% dump -0f - /usr/vhosts | ssh [email protected] "cat >remoteFile"
requires cat(1) (or dd(1), or whatever) in the jail. That takes two
seconds, but I prefer saving up my two secondses for a nice coffee.
It would probably need some warnings that the progress bar is disabled
(unknown size of file), and protection of course against directories.
Is there a better way? Is there a reason for the regular file check
that makes this a Bad Idea?
Thank you,
Kristaps
Index: sftp-client.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/sftp-client.c,v
retrieving revision 1.94
diff -u -r1.94 sftp-client.c
--- sftp-client.c 4 Dec 2010 00:18:01 -0000 1.94
+++ sftp-client.c 7 Oct 2011 19:13:03 -0000
@@ -1356,11 +1356,10 @@
return(-1);
}
if (!S_ISREG(sb.st_mode)) {
- error("%s is not a regular file", local_path);
- close(local_fd);
- return(-1);
- }
- stat_to_attrib(&sb, &a);
+ showprogress = 0;
+ attrib_clear(&a);
+ } else
+ stat_to_attrib(&sb, &a);
a.flags &= ~SSH2_FILEXFER_ATTR_SIZE;
a.flags &= ~SSH2_FILEXFER_ATTR_UIDGID;