Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions libssh2/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ def scp_recv(self, remote_path):
"""
return Channel(self._session.scp_recv(remote_path))

def scp_recv_e(self, remote_path):
"""
--writeme--
Gets a remote file via SCP Protocol. Returns a tuple of Channel and file size in bytes.

@param remote_path: absolute path of remote file to transfer
@type remote_path: str

@return: new channel opened and sb.st_size
@rtype: (L{Channel}, int)
"""
ch,sz=self._session.scp_recv_e(remote_path)
return Channel(ch),sz

def scp_send(self, path, mode, size):
"""
Sends a file to remote host via SCP protocol.
Expand Down
38 changes: 38 additions & 0 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <Python.h>
#define PYLIBSSH2_MODULE
#include "pylibssh2.h"
#include <sys/stat.h>

/* {{{ PYLIBSSH2_Session_set_banner
*/
Expand Down Expand Up @@ -634,6 +635,42 @@ PYLIBSSH2_Session_scp_recv(PYLIBSSH2_SESSION *self, PyObject *args)
}
/* }}} */

/* {{{ PYLIBSSH2_Session_scp_recv_e
*/
static char PYLIBSSH2_Session_scp_recv_e_doc[] = "\n\
scp_recv_e(remote_path) -> Tuple of libssh2.Channel and stat.st_size\n\
\n\
Requests a remote file via SCP protocol.\n\
\n\
@param remote_path: absolute path of remote file to transfer\n\
@type remote_path: str\n\
\n\
@return new channel opened and size of the requested file in bytes\n\
@rtype (libssh2.Channel, int)";

static PyObject *
PYLIBSSH2_Session_scp_recv_e(PYLIBSSH2_SESSION *self, PyObject *args)
{
char *path;
LIBSSH2_CHANNEL *channel;

if (!PyArg_ParseTuple(args, "s:scp_recv_e", &path)) {
return NULL;
}

struct stat sb;

channel = libssh2_scp_recv(self->session, path, &sb);
if (channel == NULL) {
/* CLEAN: PYLIBSSH2_CHANNEL_SCP_RECV_ERROR_MSG */
PyErr_SetString(PYLIBSSH2_Error, "SCP receive error.");
return NULL;
}

return (PyObject *)Py_BuildValue("(N,l)",PYLIBSSH2_Channel_New(channel, 1),sb.st_size);
}
/* }}} */

/* {{{ PYLIBSSH2_Session_scp_send
*/
static char PYLIBSSH2_Session_scp_send_doc[] = "\n\
Expand Down Expand Up @@ -1052,6 +1089,7 @@ static PyMethodDef PYLIBSSH2_Session_methods[] =
ADD_METHOD(session_method_pref),
ADD_METHOD(open_session),
ADD_METHOD(scp_recv),
ADD_METHOD(scp_recv_e),
ADD_METHOD(scp_send),
ADD_METHOD(sftp_init),
ADD_METHOD(direct_tcpip),
Expand Down