diff --git a/uppsrc/Core/SSH/Hosts.cpp b/uppsrc/Core/SSH/Hosts.cpp index 6796b8d3e..19530e3e6 100644 --- a/uppsrc/Core/SSH/Hosts.cpp +++ b/uppsrc/Core/SSH/Hosts.cpp @@ -17,13 +17,13 @@ bool SshHosts::Add(const String& host, const Info& info, const String& comment) libssh2_knownhost_addc( handle, ~host, - NULL, + nullptr, ~info.key, info.key.GetLength(), ~comment, comment.GetLength(), info.type | LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW, - NULL + nullptr ) == 0; return b ? b : Error(); } diff --git a/uppsrc/Core/SSH/SFtp.cpp b/uppsrc/Core/SSH/SFtp.cpp index 6dfa78ec1..adc07816b 100644 --- a/uppsrc/Core/SSH/SFtp.cpp +++ b/uppsrc/Core/SSH/SFtp.cpp @@ -187,7 +187,7 @@ bool SFtp::CopyData(Stream& dest, Stream& src, int64 maxsize) err = Format("Buffer overflow. size = %d (allowed size >= 0 && < %d", size, maxsize); goto Bailout; } - if(CopyStream(dest, src, src.GetSize(), Proxy(WhenProgress)) < 0) { + if(CopyStream(dest, src) < 0) { err = "File transfer is aborted."; goto Bailout; } @@ -200,6 +200,28 @@ Bailout: return false; } +int64 SFtp::CopyStream(Stream& dest, Stream& src) +{ + // Note: This is a modified version of Upp::CopyStream (Core/Stream.cpp, ln: 1397-1412. + // This variant reports the correct size via WhenProgress & allows us to adjsut the chunk size. + + int64 count = src.GetSize(); + int block = (int)min(count, ssh->chunk_size); + Buffer temp(block); + int loaded; + int64 done_ = 0; + int64 total_ = count; + while(count > 0 && (loaded = src.Get(~temp, (int)min(count, block))) > 0) { + dest.Put(~temp, loaded); + count -= loaded; + done_ += loaded; + if(WhenProgress(done_, total_)) + return -1; + } + LLOG(Format("%d of %d bytes successfully transferred.", done_, total_)); + return done_; +} + bool SFtp::SaveFile(const char *path, const String& data) { StringStream in(data); diff --git a/uppsrc/Core/SSH/SFtp.h b/uppsrc/Core/SSH/SFtp.h index a24f43b97..68532b4ce 100644 --- a/uppsrc/Core/SSH/SFtp.h +++ b/uppsrc/Core/SSH/SFtp.h @@ -154,6 +154,7 @@ private: bool Read(SFtpHandle handle, void* ptr, int size); bool Write(SFtpHandle handle, const void* ptr, int size); bool CopyData(Stream& dest, Stream& src, int64 maxsize = INT64_MAX); + int64 CopyStream(Stream& dest, Stream& src); One sftp_session; int done; diff --git a/uppsrc/Core/SSH/Session.cpp b/uppsrc/Core/SSH/Session.cpp index 7d839f3a9..fa30e871c 100644 --- a/uppsrc/Core/SSH/Session.cpp +++ b/uppsrc/Core/SSH/Session.cpp @@ -167,6 +167,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const #endif libssh2_session_set_blocking(ssh->session, 0); ssh->socket = &session->socket; + LLOG("Session successfully initialized."); WhenConfig(); return true; })) goto Bailout;