diff --git a/CHANGES b/CHANGES
index bd74340897cf5e69ae20434383d1985f19a216b6..37553ee0c4e2a0d27f108dda0f146c5c3e93f58c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,8 @@
                                   Changelog
 
 Daniel Stenberg (22 Dec 2008)
+- Given a recent enough libssh2, libcurl can now seek/resume with SFTP even
+  on file indexes beyond 2 or 4GB.
 
 - Anthony Bryan provided a set of patches that cleaned up manual language,
   corrected spellings and more.
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index fff8f41a83663d49fb01b68fe07c7e133249fa66..5783b5eaecf283aaf3358bc3a7900be8baed681d 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -37,6 +37,7 @@ This release includes the following bugfixes:
  o curl_multi_timeout() no longer returns timeout 0 when there's nothing to do
    yet
  o the multi_socket API and HTTP pipelining now work a lot better when combined
+ o SFTP seek/resume beyond 32bit file sizes
 
 This release includes the following known bugs:
 
diff --git a/lib/ssh.c b/lib/ssh.c
index c1aa48fd9f3030bbbe0f7eb5da828412956609bf..339c2db2a76cb3adccb520fad4ee0d23d02c8cb2 100644
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -431,6 +431,16 @@ static CURLcode ssh_getworkingpath(struct connectdata *conn,
   return CURLE_OK;
 }
 
+/*
+ * Earlier libssh2 versions didn't have the ability to seek to 64bit positions
+ * with 32bit size_t.
+ */
+#ifdef HAVE_LIBSSH2_SFTP_SEEK2
+#define SFTP_SEEK(x,y) libssh2_sftp_seek2(x, (libssh2_uint64_t)y)
+#else
+#define SFTP_SEEK(x,y) libssh2_sftp_seek(x, y)
+#endif
+
 /*
  * ssh_statemach_act() runs the SSH statemachine "one round" and returns.  The
  * data the pointer 'block' points to will be set to TRUE if the libssh2
@@ -1343,7 +1353,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
         Curl_pgrsSetUploadSize(data, data->set.infilesize);
       }
 
-      libssh2_sftp_seek(sshc->sftp_handle, data->state.resume_from);
+      SFTP_SEEK(sshc->sftp_handle, data->state.resume_from);
     }
     if(data->set.infilesize>0) {
       data->req.size = data->set.infilesize;
@@ -1716,7 +1726,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
           size = to - from + 1;
         }
 
-        libssh2_sftp_seek(conn->proto.sshc.sftp_handle, from);
+        SFTP_SEEK(conn->proto.sshc.sftp_handle, from);
       }
       data->req.size = size;
       data->req.maxdownload = size;
@@ -1750,7 +1760,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
       data->req.maxdownload = attrs.filesize - data->state.resume_from;
       Curl_pgrsSetDownloadSize(data,
                                attrs.filesize - data->state.resume_from);
-      libssh2_sftp_seek(sshc->sftp_handle, data->state.resume_from);
+      SFTP_SEEK(sshc->sftp_handle, data->state.resume_from);
     }
   }
   /* Setup the actual download */