I need a simple functionality of scp.
I've got some progress with a file reading on server.
I've opened a channel and then I've done this:
...
std::vector<std::string> execParams;
do
{
message = ssh_message_get(session);
if (ssh_message_type(message) == SSH_REQUEST_CHANNEL &&
ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_EXEC)
{
std::string command(message->channel_request.command);
execParams = string_split(command, " ");
if (!execParams.empty() && execParams[0] == "scp")
{
ssh_message_channel_request_reply_success(message);
ssh_message_free(message);
scpSession = true;
break;
}
}
} while (!scpSession);
if (scpSession)
{
if (execParams[1] == "-t")
{
// this is "write" of a client
scpMode = SSH_SCP_READ;
ssh_channel_write(chan, "", 1);
}
else if (execParams[1] == "-f")
{
// this "read" of a client
scpMode = SSH_SCP_WRITE;
}
scp = ssh_scp_new(session, scpMode, "D:/test/scp");
//using already oned channel
scp->channel = chan;
if (scp->mode == SSH_SCP_WRITE)
scp->state = SSH_SCP_WRITE_INITED;
else
scp->state = SSH_SCP_READ_INITED;
bool exit = false;
char buffer[16384];
do {
int r = ssh_scp_pull_request(scp);
...
}
}
It's working only for client write operations and need improving but am I
moving in right direction?
Also is there any example of how to create sftp server?
2015-07-08 18:56 GMT+03:00 Andreas Schneider <[email protected]>:
> On Wednesday 08 July 2015 16:05:11 Игорь Коваленко wrote:
> > Hello!
> >
> > I need to create ssh server with scp functionality but I can't find any
> > examples. How should I handle scp request and initialize new scp session?
>
> Why don't you use sftp?
>
> --
> Andreas Schneider GPG-ID: CC014E3D
> www.cryptomilk.org [email protected]
>
>
>