SFtp: CopyStream has replaced the Upp::CopyStream.

git-svn-id: svn://ultimatepp.org/upp/trunk@12185 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
oblivion 2018-08-25 19:20:22 +00:00
parent 8617791d5a
commit dcf1ac1dda
4 changed files with 27 additions and 3 deletions

View file

@ -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();
}

View file

@ -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<int64>(count, ssh->chunk_size);
Buffer<byte> temp(block);
int loaded;
int64 done_ = 0;
int64 total_ = count;
while(count > 0 && (loaded = src.Get(~temp, (int)min<int64>(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);

View file

@ -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<LIBSSH2_SFTP*> sftp_session;
int done;

View file

@ -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;