cURL / Mailing Lists / curl-library / Single Mail


Re: Stall when uploading to sftp using multi interface

From: Henry Ludemann <>
Date: Mon, 28 Feb 2011 18:41:57 +0800


Henry Ludemann wrote:
> Henry Ludemann wrote:
>> I've sent a pull request with a proper fix
> Sorry, hold off on this. It's still got issues.

There are several bugs in curl related to sftp upload using the multi
interface, two of which I'm comfortable fixing, one that I'm not so
sure about.

1. In ssh_statemach_act it doesn't reset the cselect_bits variable.
This is required so the curl multi interface will attempt to send
immediately, instead of the next 'curl_multi_socket_action' (which
will never happen, as ssh isn't waiting on any sockets or timeouts, so
there is no reason to call back into curl). This had been fixed for
SSH_SFTP_UPLOAD_INIT [patch-1] [patch-2].

2. In Curl_readwrite it should use 'waitfor' when considering if it is
ready for calling readwrite_upload [patch-3]. This is required because
at the end of the sftp upload we only want to read from the socket,
not write to it. This means the 'select_res & CURL_CSELECT_OUT' is
always false, as libssh2 indicates that we don't want to write to the
socket, only read from it.

3. In Curl_readwrite, we populate the buffer and send it using
sftp_send. When this call successfully transfers the data, it resets
waitfor to 0 (as the current transfer has succeeded). In
readwrite_upload (called from Curl_readwrite) we only clear k->keepon
if upload_done is true, which apparently only happens for chunked http
uploads. As k->keepon is not cleared, back in Curl_readwrite '*done'
is set to false, as keepon is non-zero. This means we never leave

I'm not sure of the right way to fix this; any suggestions would be
gratefully accepted. I'll keep debugging.


[patch-1] Patch for the curl cselect_bits variable -

[patch-2] Document why we need to reset cselect_bits -

[patch-3] Use 'waitfor' when available to see if we're ready for
uploading -
List admin:
Received on 2011-02-28