1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

SFTP: stat remote file also when CURLOPT_NOBODY is 1

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
This commit is contained in:
Fabian Frank 2014-01-20 13:14:04 -08:00 committed by Daniel Stenberg
parent 82de54dd38
commit 852a018e78

View File

@ -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 */