data streaming using SFTP

joshua stein jcs at superblock.net
Wed Oct 11 15:13:29 EST 2006


> Why must you use SFTP, which is a "file transfer protocol"?
> 
> What you want is trivial with straight SSH:

because sometimes the host you're connecting to only provides sftp
access without a real shell that can run arbitrary commands.  such
is the case with a backup provider like strongspace.com.

sftp(1) refuses to upload from /dev/stdin, but if the checks are
altered with the hack below (against openbsd src), it works, but
it's not pretty:

    $ echo "put /dev/stdin some-remote-file" > ~/a
    $ tar -czf - / | sftp -b ~/a some-remote-host

the batch mode is necessary because otherwise sftp wants to read
commands from stdin instead of the data you want to transfer.  it
would be nice to be able to read the put command from an argument
and accept "-" as an input file.

-- 
joshua stein :: superblock :: http://superblock.net/


Index: sftp-client.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/sftp-client.c,v
retrieving revision 1.74
diff -u -r1.74 sftp-client.c
--- sftp-client.c	3 Aug 2006 03:34:42 -0000	1.74
+++ sftp-client.c	11 Oct 2006 04:58:03 -0000
@@ -1013,7 +1013,7 @@
 		close(local_fd);
 		return(-1);
 	}
-	if (!S_ISREG(sb.st_mode)) {
+	if (!(S_ISREG(sb.st_mode) || S_ISFIFO(sb.st_mode))) {
 		error("%s is not a regular file", local_path);
 		close(local_fd);
 		return(-1);
Index: sftp.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/sftp.c,v
retrieving revision 1.92
diff -u -r1.92 sftp.c
--- sftp.c	19 Sep 2006 05:52:23 -0000	1.92
+++ sftp.c	11 Oct 2006 04:58:04 -0000
@@ -492,7 +492,7 @@
 	if (stat(path, &sb) == -1)
 		fatal("stat %s: %s", path, strerror(errno));
 
-	return(S_ISREG(sb.st_mode));
+	return(S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode));
 }
 
 static int



More information about the openssh-unix-dev mailing list