ultimatepp/uppsrc/Core/SSH/SFtpStream.cpp
oblivion 810ea1ec95 Core/SSH: Z compression is enabled. (uses plugin/z on WIN32)
Core/SSH: A CLANG warning (-Wimplicit-function-declaration) condition for gettimeofday() function is fixed. 
Core/SSH: Cleanup, small bugfixes and cosmetics..
Core/SSH: API docs are updated accordingly.

git-svn-id: svn://ultimatepp.org/upp/trunk@14509 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2020-05-28 13:22:30 +00:00

80 lines
No EOL
1.3 KiB
C++

#include "SSH.h"
namespace Upp {
void SFtpStream::SetPos(int64 pos)
{
sftp->Seek(handle, pos);
}
void SFtpStream::SetStreamSize(int64 size)
{
// TODO
}
dword SFtpStream::Read(int64 at, void *ptr, dword size)
{
SetPos(at);
return sftp->Get(handle, ptr, size);
}
void SFtpStream::Write(int64 at, const void *data, dword size)
{
SetPos(at);
sftp->Put(handle, data, size);
if(sftp->IsError())
SetError();
}
void SFtpStream::Close()
{
if(handle) {
Flush();
sftp->Close(handle);
handle = NULL;
}
}
bool SFtpStream::IsOpen() const
{
return handle;
}
bool SFtpStream::Open(SFtp& sftp_, const char *filename, dword mode, int acm)
{
if(IsOpen())
Close();
sftp = &sftp_;
int iomode = mode & ~SHAREMASK;
handle = sftp->Open(filename, iomode == READ ? SFtp::READ :
iomode == CREATE ? SFtp::READ|SFtp::WRITE|SFtp::CREATE|SFtp::TRUNCATE :
SFtp::READ|SFtp::WRITE, acm);
if(handle) {
SFtpAttrs attrs;
if(!sftp->GetAttrs(handle, attrs)) {
Close();
return false;
}
OpenInit(mode, attrs.filesize);
}
return handle;
}
SFtpStream::SFtpStream(SFtp& sftp, const char *filename, dword mode, int acm)
: SFtpStream()
{
Open(sftp, filename, mode, acm);
}
SFtpStream::SFtpStream()
: sftp(nullptr)
, handle(nullptr)
{
}
SFtpStream::~SFtpStream()
{
Close();
}
};