------=_Part_593_2818722.1110929713316
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,
We plan to do automated file transfers with SFTP where an uploaded
file is always appended on the server, and I made this patch to
support that. The patch

1. adds the "ap" command to the client (syntax just like the put command)

2. adds in both client and server support for the SSH2_FXF_APPEND flag
of the "pflags" field of the file open message.

Patch is against 4.0p1.

Thanks,
Pete Dow

------=_Part_593_2818722.1110929713316
Content-Type: text/plain; name="openssh-4.0p1-append-changes.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="openssh-4.0p1-append-changes.diff"

diff -aur openssh-4.0p1.orig/sftp.c openssh-4.0p1/sftp.c
--- openssh-4.0p1.orig/sftp.c=092005-03-01 10:16:48.000000000 +0000
+++ openssh-4.0p1/sftp.c=092005-03-15 23:15:55.942262504 +0000
@@ -103,6 +103,7 @@
#define I_SYMLINK=0921
#define I_VERSION=0922
#define I_PROGRESS=0923
+#define I_APPEND=0924
=20
struct CMD {
=09const char *c;
@@ -110,6 +111,7 @@
};
=20
static const struct CMD cmds[] =3D {
+=09{ "ap",=09=09I_APPEND },
=09{ "bye",=09I_QUIT },
=09{ "cd",=09=09I_CHDIR },
=09{ "chdir",=09I_CHDIR },
@@ -189,6 +191,7 @@
=09printf("mkdir path Create remote directory\n");
=09printf("progress Toggle display of progress meter\=
n");
=09printf("put local-path [remote-path] Upload file\n");
+=09printf("ap local-path [remote-path] Upload and append file\n");
=09printf("pwd Display remote working directory\=
n");
=09printf("exit Quit sftp\n");
=09printf("quit Quit sftp\n");
@@ -569,7 +572,7 @@
}
=20
static int
-process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int p=
flag)
+process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int p=
flag, int append)
{
=09char *tmp_dst =3D NULL;
=09char *abs_dst =3D NULL;
@@ -629,7 +632,7 @@
=09=09=09abs_dst =3D make_absolute(tmp, pwd);
=20
=09=09printf("Uploading %s to %s\n", g.gl_pathv[i], abs_dst);
-=09=09if (do_upload(conn, g.gl_pathv[i], abs_dst, pflag) =3D=3D -1)
+=09=09if (do_upload(conn, g.gl_pathv[i], abs_dst, pflag, append) =3D=3D -1=
)
=09=09=09err =3D -1;
=09}
=20
@@ -897,6 +900,7 @@
=09switch (cmdnum) {
=09case I_GET:
=09case I_PUT:
+=09case I_APPEND:
=09=09if (parse_getput_flags(&cp, pflag))
=09=09=09return(-1);
=09=09/* Get first pathname (mandatory) */
@@ -1032,7 +1036,8 @@
=09=09err =3D process_get(conn, path1, path2, *pwd, pflag);
=09=09break;
=09case I_PUT:
-=09=09err =3D process_put(conn, path1, path2, *pwd, pflag);
+=09case I_APPEND:
+=09=09err =3D process_put(conn, path1, path2, *pwd, pflag, cmdnum=3D=3DI_A=
PPEND);
=09=09break;
=09case I_RENAME:
=09=09path1 =3D make_absolute(path1, *pwd);
diff -aur openssh-4.0p1.orig/sftp-client.c openssh-4.0p1/sftp-client.c
--- openssh-4.0p1.orig/sftp-client.c=092004-12-06 11:43:43.000000000 +0000
+++ openssh-4.0p1/sftp-client.c=092005-03-15 23:15:55.944262200 +0000
@@ -976,7 +976,7 @@
=20
int
do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
- int pflag)
+ int pflag, int append_file)
{
=09int local_fd, status;
=09u_int handle_len, id, type;
@@ -1029,7 +1029,10 @@
=09buffer_put_char(&msg, SSH2_FXP_OPEN);
=09buffer_put_int(&msg, id);
=09buffer_put_cstring(&msg, remote_path);
-=09buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC);
+=09if (append_file)
+=09=09buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_APPEND);
+=09else
+=09=09buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC);=
=09
=09encode_attrib(&msg, &a);
=09send_msg(conn->fd_out, &msg);
=09debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, remote_path);
diff -aur openssh-4.0p1.orig/sftp-client.h openssh-4.0p1/sftp-client.h
--- openssh-4.0p1.orig/sftp-client.h=092004-12-06 11:45:54.000000000 +0000
+++ openssh-4.0p1/sftp-client.h=092005-03-15 23:15:55.945262048 +0000
@@ -92,8 +92,8 @@
=20
/*
* Upload 'local_path' to 'remote_path'. Preserve permissions and times
- * if 'pflag' is set
+ * if 'pflag' is set. Append instead of truncate if append_file is set.
*/
-int do_upload(struct sftp_conn *, char *, char *, int);
+int do_upload(struct sftp_conn *, char *, char *, int, int);
=20
#endif
diff -aur openssh-4.0p1.orig/sftp-server.c openssh-4.0p1/sftp-server.c
--- openssh-4.0p1.orig/sftp-server.c=092004-07-17 04:07:42.000000000 +0000
+++ openssh-4.0p1/sftp-server.c=092005-03-15 23:15:55.946261896 +0000
@@ -94,6 +94,10 @@
=09} else if (pflags & SSH2_FXF_WRITE) {
=09=09flags =3D O_WRONLY;
=09}
+=09if ((pflags & SSH2_FXF_WRITE) &&
+=09 (pflags & SSH2_FXF_APPEND)) {
+=09=09flags |=3D O_APPEND;
+=09}
=09if (pflags & SSH2_FXF_CREAT)
=09=09flags |=3D O_CREAT;
=09if (pflags & SSH2_FXF_TRUNC)

------=_Part_593_2818722.1110929713316
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
http://www.mindrot.org/mailman/listi...enssh-unix-dev

------=_Part_593_2818722.1110929713316--