]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ssh: Add support for libssh2 read timeout
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>
Wed, 26 Apr 2023 08:44:57 +0000 (09:44 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 15 May 2023 11:20:47 +0000 (13:20 +0200)
Hook the new (1.11.0 or newer) libssh2 support for setting a read timeout
into the SERVER_RESPONSE_TIMEOUT option.  With this done, clients can use
the standard curl response timeout setting to also control the time that
libssh2 will wait for packets from a slow server.  This is necessary to
enable use of very slow SFTP servers.

Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
Closes #10965

docs/libcurl/opts/CURLOPT_SERVER_RESPONSE_TIMEOUT.3
lib/vssh/libssh2.c

index 69d892e655c476b3a78cbc2d72b082d51a085a46..46d6fdaa7437a473a47e552c09aef10e0226779d 100644 (file)
@@ -45,7 +45,7 @@ This option was formerly known as \fBCURLOPT_FTP_RESPONSE_TIMEOUT\fP.
 .SH DEFAULT
 None
 .SH PROTOCOLS
-FTP, IMAP, POP3 and SMTP
+FTP, IMAP, POP3, SMTP, and SSH
 .SH EXAMPLE
 .nf
 CURL *curl = curl_easy_init();
@@ -60,6 +60,9 @@ if(curl) {
 .fi
 .SH AVAILABILITY
 Added in 7.10.8. Used under this name since 7.20.0
+
+Support for SSH is predicated on a new enough (1.11.0) version of libssh2
+being available when compiling libcurl.
 .SH RETURN VALUE
 Returns CURLE_OK if supported, and CURLE_UNKNOWN_OPTION if not. Returns
 CURLE_BAD_FUNCTION_ARGUMENT if set to a negative value or a value that when
index dd39a844c646b905003e6b1605039af13cce9f3e..14c2784fe3c144ed65e4e74ba3fd3bb69e9bb8f5 100644 (file)
@@ -3280,6 +3280,16 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done)
     return CURLE_FAILED_INIT;
   }
 
+#ifdef HAVE_LIBSSH2_VERSION
+  /* Set the packet read timeout if the libssh2 version supports it */
+#if LIBSSH2_VERSION_NUM >= 0x010B00
+  if(data->set.server_response_timeout > 0) {
+    libssh2_session_set_read_timeout(sshc->ssh_session,
+                                     data->set.server_response_timeout / 1000);
+  }
+#endif
+#endif
+
 #ifndef CURL_DISABLE_PROXY
   if(conn->http_proxy.proxytype == CURLPROXY_HTTPS) {
     /*