]> granicus.if.org Git - curl/commitdiff
Added support for --append on SFTP uploads. Unfortunately, OpenSSH doesn't
authorDan Fandrich <dan@coneharvesters.com>
Fri, 1 Aug 2008 18:41:14 +0000 (18:41 +0000)
committerDan Fandrich <dan@coneharvesters.com>
Fri, 1 Aug 2008 18:41:14 +0000 (18:41 +0000)
support this so it goes untested.

CHANGES
RELEASE-NOTES
docs/MANUAL
docs/curl.1
lib/ssh.c
src/main.c

diff --git a/CHANGES b/CHANGES
index 96aa26708c365faf8dece93b6fc0738919093349..0cb007fdcb94a09ae9392df4a03bdeff1b48f55f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,10 @@
 
                                   Changelog
 
+Daniel Fandrich (1 Aug 2008)
+- Added support for --append on SFTP uploads. Unfortunately, OpenSSH doesn't
+  support this so it goes untested.
+
 Yang Tse (1 Aug 2008)
 - Configure process now checks if the preprocessor _REENTRANT symbol is already
   defined. If it isn't currently defined a set of checks are performed to test
index a0ddeaf42dc464fe5fa3f444e01e225d737e0db5..58484814bded3dcb860cf5a3b5d5e08b9b4ee2d4 100644 (file)
@@ -20,6 +20,7 @@ This release includes the following changes:
  o Added test selection by key word in runtests.pl
  o the curl tool's -w option support the %{ssl_verify_result} variable
  o Added CURLOPT_SCOPE and scope parsing of the URL according to RFC4007
+ o Support --append on SFTP uploads (not with OpenSSH, though)
 
 This release includes the following bugfixes:
 
index 3b1195c0b0fb1e2c1ac158a45e3e4190dd71e6ea..3aea5d40f41d115927ccd6fd3e4fa734d8f0fd2b 100644 (file)
@@ -48,6 +48,9 @@ SIMPLE USAGE
         curl -u username: --key ~/.ssh/id_dsa --pubkey ~/.ssh/id_dsa.pub \
                scp://shell.example.com/~/personal.txt
 
+  Get the main page from an IPv6 web server:
+
+        curl -g "http://[2001:1890:1112:1::20]/"
 
 DOWNLOAD TO A FILE
 
@@ -86,6 +89,13 @@ USING PASSWORDS
    standards while the recommended "explicit" way is done by using FTP:// and
    the --ftp-ssl option.
 
+ SFTP / SCP
+
+   This is similar to FTP, but you can specify a private key to use instead of
+   a password. Note that the private key may itself be protected by a password
+   that is unrelated to the login password of the remote system.  If you
+   provide a private key file you must also provide a public key file.
+
  HTTP
 
    Curl also supports user and password in HTTP URLs, thus you can pick a file
@@ -154,9 +164,9 @@ RANGES
 
 UPLOADING
 
- FTP
+ FTP / FTPS / SFTP / SCP
 
-  Upload all data on stdin to a specified ftp site:
+  Upload all data on stdin to a specified server:
 
         curl -T - ftp://ftp.upload.com/myfile
 
@@ -169,7 +179,7 @@ UPLOADING
  
         curl -T uploadfile -u user:passwd ftp://ftp.upload.com/
 
-  Upload a local file to get appended to the remote file using ftp:
+  Upload a local file to get appended to the remote file:
 
         curl -T localfile -a ftp://ftp.upload.com/remotefile
 
@@ -331,7 +341,7 @@ REFERRER
 
         curl -e www.coolsite.com http://www.showme.com/
 
-  NOTE: The referer field is defined in the HTTP spec to be a full URL.
+  NOTE: The Referer: [sic] field is defined in the HTTP spec to be a full URL.
 
 USER AGENT
 
@@ -564,6 +574,14 @@ FTP and PATH NAMES
 
   (I.e with an extra slash in front of the file name.)
 
+SFTP and SCP and PATH NAMES
+
+  With sftp: and scp: URLs, the path name given is the absolute name on the
+  server. To access a file relative to the remote user's home directory,
+  prefix the file with /~/ , such as:
+
+        curl -u $USER sftp://home.example.com/~/.bashrc
+
 FTP and firewalls
 
   The FTP protocol requires one of the involved parties to open a second
@@ -875,7 +893,8 @@ MULTIPLE TRANSFERS WITH A SINGLE COMMAND LINE
   As is mentioned above, you can download multiple files with one command line
   by simply adding more URLs. If you want those to get saved to a local file
   instead of just printed to stdout, you need to add one save option for each
-  URL you specify. Note that this also goes for the -O option.
+  URL you specify. Note that this also goes for the -O option (but not
+  --remote-name-all).
 
   For example: get two files and use -O for the first and a custom file
   name for the second:
index a87e1cc0941ea538024943d780d46c18dadf8a56..a23f156a404906f70e4cd06c74626b60b75c3643 100644 (file)
@@ -106,8 +106,9 @@ the --option version of them. (This concept with --no options was added in
 7.19.0. Previously most options were toggled on/off on repeated use of the
 same command line option.)
 .IP "-a/--append"
-(FTP) When used in an FTP upload, this will tell curl to append to the target
+(FTP/SFTP) When used in an upload, this will tell curl to append to the target
 file instead of overwriting it. If the file doesn't exist, it will be created.
+Note that this flag is ignored by some SSH servers (including OpenSSH).
 .IP "-A/--user-agent <agent string>"
 (HTTP) Specify the User-Agent string to send to the HTTP server. Some badly
 done CGIs fail if this field isn't set to "Mozilla/4.0". To encode blanks in
index cb6e96c780065f75a0e3280aa499e99cb10dcf41..ce6f4f04dac62eebae727422101540b5d4c44084 100644 (file)
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -1198,6 +1198,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
     break;
 
   case SSH_SFTP_UPLOAD_INIT:
+  {
+    unsigned long flags;
     /*
      * NOTE!!!  libssh2 requires that the destination path is a full path
      *          that includes the destination file and name OR ends in a "/"
@@ -1221,13 +1223,19 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
       }
     }
 
+    if(data->set.ftp_append)
+      /* Try to open for append, but create if nonexisting */
+      flags = LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_APPEND;
+    else if (data->state.resume_from > 0)
+      /* If we have restart position then open for append */
+      flags = LIBSSH2_FXF_WRITE|LIBSSH2_FXF_APPEND;
+    else
+      /* Clear file before writing (normal behaviour) */
+      flags = LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC;
+
     sshc->sftp_handle =
       libssh2_sftp_open(sshc->sftp_session, sftp_scp->path,
-                        /* If we have restart position then open for append */
-                        (data->state.resume_from > 0)?
-                        LIBSSH2_FXF_WRITE|LIBSSH2_FXF_APPEND:
-                        LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
-                        data->set.new_file_perms);
+                        flags, data->set.new_file_perms);
 
     if(!sshc->sftp_handle) {
       if(libssh2_session_last_errno(sshc->ssh_session) ==
@@ -1322,6 +1330,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
       state(conn, SSH_STOP);
     }
     break;
+  }
 
   case SSH_SFTP_CREATE_DIRS_INIT:
     if(strlen(sftp_scp->path) > 1) {
index eea21a23695d3632b2f9b79c4f64d33d402cdfea..ceee05bddf9b4e8f8ec48404931eb4536fcb54b9 100644 (file)
@@ -651,7 +651,7 @@ static void help(void)
     "Usage: curl [options...] <url>",
     "Options: (H) means HTTP/HTTPS only, (F) means FTP only",
     "    --anyauth       Pick \"any\" authentication method (H)",
-    " -a/--append        Append to target file when uploading (F)",
+    " -a/--append        Append to target file when uploading (F/SFTP)",
     "    --basic         Use HTTP Basic Authentication (H)",
     "    --cacert <file> CA certificate to verify peer against (SSL)",
     "    --capath <directory> CA directory to verify peer against (SSL)",