]> granicus.if.org Git - curl/commitdiff
SFTP: stat remote file also when CURLOPT_NOBODY is 1
authorFabian Frank <fabian@pagefault.de>
Mon, 20 Jan 2014 21:14:04 +0000 (13:14 -0800)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 20 Jan 2014 21:57:55 +0000 (22:57 +0100)
Make it possible to call
curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize)
and related functions on remote sftp:// files, without downloading them.

Reported-by: Yingwei Liu
Bug: http://curl.haxx.se/mail/lib-2014-01/0139.html

lib/ssh.c

index 9838c95794253f64b10a4ee149b8a4c2a0d81fba..80906d814da946f29ba4f1d13abb79e26931d525 100644 (file)
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -1568,9 +1568,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
       if(data->set.upload)
         state(conn, SSH_SFTP_UPLOAD_INIT);
       else {
-        if(data->set.opt_no_body)
-          state(conn, SSH_STOP);
-        else if(sftp_scp->path[strlen(sftp_scp->path)-1] == '/')
+        if(sftp_scp->path[strlen(sftp_scp->path)-1] == '/')
           state(conn, SSH_SFTP_READDIR_INIT);
         else
           state(conn, SSH_SFTP_DOWNLOAD_INIT);
@@ -1808,6 +1806,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
       break;
 
     case SSH_SFTP_READDIR_INIT:
+      Curl_pgrsSetDownloadSize(data, -1);
+      if(data->set.opt_no_body)
+        state(conn, SSH_STOP);
+
       /*
        * This is a directory that we are trying to get, so produce a directory
        * listing
@@ -2065,6 +2067,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          */
         data->req.size = -1;
         data->req.maxdownload = -1;
+        Curl_pgrsSetDownloadSize(data, -1);
       }
       else {
         curl_off_t size = attrs.filesize;
@@ -2142,6 +2145,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
         SFTP_SEEK(sshc->sftp_handle, data->state.resume_from);
       }
     }
+
+    if(data->set.opt_no_body)
+      state(conn, SSH_SFTP_CLOSE);
+
     /* Setup the actual download */
     if(data->req.size == 0) {
       /* no data to transfer */