mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
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:
parent
8617791d5a
commit
dcf1ac1dda
4 changed files with 27 additions and 3 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue