Daniele Calore
2007-May-14 21:30 UTC
[PATCH] Adds support for Append command (SSH_FXF_APPEND) to sftp_client
Dear list, Attached is a patch that implements the "append" command in a sftp session, as describe in "draft-ietf-secsh-filexfer-01" and further releases. It is for and had been tested on the current version of OpenSSH (the Portable CVS) and it works, also against non patched versions. The patch is "simple" it it just like the "do_upload" function in "sftp-client.c". Pseudo Instruction of the new "do_append" function: 1) stat_remote_file This will return an Attrib struct to know the remote file size. 2) open_remote_file Open the remote file without the "SSH2_FXF_TRUNC" flag and with SSH2_FXF_APPEND flag. 3) write_to_remote_file It is like the "do_upload" function, expect that the offset does not start with a '0' but it is set to the value returned by "stat_remote_file". More in depth I have use the function "do_fstat" to retrive remote_file size. The function "do_fstat" is never used, but is still present, in the "sftp-client.c" ... so why not to use it ? I hope this patch will be included in future release of OpenSSH, or at least that you will consider to reimplement it in a better way. Let me know if ... * Some notes: I have also revisited "sftp.c". There is now a new I_APPEND Command, that has number "1" for alphabetic reason. If you do not plan to insert this patch consider to change this line of code: --- sftp.c.orig 2007-05-14 22:48:33.000000000 +0200 +++ sftp.c 2007-05-14 22:50:07.000000000 +0200 @@ -940,7 +940,7 @@ return(-1); if (get_pathname(&cp, path2)) return(-1); - if (!*path1 || !*path2) { + if (*path1 == NULL || *path2 == NULL) { error("You must specify two paths after a %s " "command.", cmd); return(-1); And maybe remove also the "do_fstat" function in "sftp-client.c" (it is never used) We can also patch the "sftp-server.c" to honor the APPEND flag, but there is no way for the client to know if the server is patched or not... * Suggestions: 1) Change the SSH2_FILEXFER_VERSION to something new. 2) Implement a VENDOR specific future to retrive the presence of the new SSH2_FXF_APPEND future. We can do this using the SSH2_FXP_EXTENDED command. (This will be useful also for other patches; like the SSH_FXP_LINK patch) If you want I can make a patch also for the server side. Best regards, -- Daniele Calore ( orkaan at orkaan.org ) -------------- next part -------------- A non-text attachment was scrubbed... Name: openssh-sftp-append-pcvs.patch Type: text/x-patch Size: 9173 bytes Desc: not available Url : http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20070514/ab71f883/attachment.bin