From 4f951461517f3c5430fa87c1594c5f8e6756662c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 20 Aug 2009 10:50:02 +0200 Subject: Fix build warnings on Windows. --- libssh/scp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libssh/scp.c') diff --git a/libssh/scp.c b/libssh/scp.c index c0ebac0..0ca7b44 100644 --- a/libssh/scp.c +++ b/libssh/scp.c @@ -21,9 +21,11 @@ * MA 02111-1307, USA. */ -#include "libssh/priv.h" +#include #include +#include "libssh/priv.h" + /** @brief Creates a new scp session * @param session the SSH session to use * @param mode one of SSH_SCP_WRITE or SSH_SCP_READ, depending if you need to drop files remotely or read them. @@ -136,7 +138,7 @@ int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, const char ssh_set_error(scp->session,SSH_FATAL,"ssh_scp_push_file called under invalid state"); return SSH_ERROR; } - snprintf(buffer,sizeof(buffer),"C%s %ld %s\n",perms, size, filename); + snprintf(buffer, sizeof(buffer), "C%s %" PRIdS " %s\n", perms, size, filename); r=channel_write(scp->channel,buffer,strlen(buffer)); if(r==SSH_ERROR){ scp->state=SSH_SCP_ERROR; -- cgit From 6801959989defc3c360c5b7dc16c5bcc6a0f9c6b Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Sun, 23 Aug 2009 14:28:38 +0200 Subject: Use ssh_basename on ssh_scp_file_push'ed files --- libssh/scp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libssh/scp.c') diff --git a/libssh/scp.c b/libssh/scp.c index 0ca7b44..06725e3 100644 --- a/libssh/scp.c +++ b/libssh/scp.c @@ -134,11 +134,14 @@ int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, const char char buffer[1024]; int r; uint8_t code; + char *file; if(scp->state != SSH_SCP_WRITE_INITED){ ssh_set_error(scp->session,SSH_FATAL,"ssh_scp_push_file called under invalid state"); return SSH_ERROR; } - snprintf(buffer, sizeof(buffer), "C%s %" PRIdS " %s\n", perms, size, filename); + file=ssh_basename(filename); + snprintf(buffer, sizeof(buffer), "C%s %" PRIdS " %s\n", perms, size, file); + SAFE_FREE(file); r=channel_write(scp->channel,buffer,strlen(buffer)); if(r==SSH_ERROR){ scp->state=SSH_SCP_ERROR; -- cgit From 049c62098cbd0d8efc342150a194fe72c9bdf6b0 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Sun, 23 Aug 2009 14:57:03 +0200 Subject: add ssh_scp_push_directory,ssh_scp_leave_directory Not yet carefully tested --- libssh/scp.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'libssh/scp.c') diff --git a/libssh/scp.c b/libssh/scp.c index 06725e3..9035c44 100644 --- a/libssh/scp.c +++ b/libssh/scp.c @@ -123,6 +123,69 @@ void ssh_scp_free(ssh_scp scp){ SAFE_FREE(scp); } +/** @brief creates a directory in a scp in sink mode + * @param dirname Name of the directory being created. + * @param perms Text form of the unix permissions for the new directory, e.g. "0755". + * @returns SSH_OK if the directory was created. + * @returns SSH_ERROR if an error happened. + * @see ssh_scp_leave_directory + */ +int ssh_scp_push_directory(ssh_scp scp, const char *dirname, const char *perms){ + char buffer[1024]; + int r; + uint8_t code; + char *dir; + if(scp->state != SSH_SCP_WRITE_INITED){ + ssh_set_error(scp->session,SSH_FATAL,"ssh_scp_push_directory called under invalid state"); + return SSH_ERROR; + } + dir=ssh_basename(dirname); + snprintf(buffer, sizeof(buffer), "D%s 0 %s\n", perms, dir); + SAFE_FREE(dir); + r=channel_write(scp->channel,buffer,strlen(buffer)); + if(r==SSH_ERROR){ + scp->state=SSH_SCP_ERROR; + return SSH_ERROR; + } + r=channel_read(scp->channel,&code,1,0); + if(code != 0){ + ssh_set_error(scp->session,SSH_FATAL, "scp status code %ud not valid", code); + scp->state=SSH_SCP_ERROR; + return SSH_ERROR; + } + return SSH_OK; +} + +/** + * @brief Leaves a directory + * @returns SSH_OK if the directory was created. + * @returns SSH_ERROR if an error happened. + * @see ssh_scp_push_directory + */ + int ssh_scp_leave_directory(ssh_scp scp){ + char buffer[1024]; + int r; + uint8_t code; + if(scp->state != SSH_SCP_WRITE_INITED){ + ssh_set_error(scp->session,SSH_FATAL,"ssh_scp_leave_directory called under invalid state"); + return SSH_ERROR; + } + strcpy(buffer, "E\n"); + r=channel_write(scp->channel,buffer,strlen(buffer)); + if(r==SSH_ERROR){ + scp->state=SSH_SCP_ERROR; + return SSH_ERROR; + } + r=channel_read(scp->channel,&code,1,0); + if(code != 0){ + ssh_set_error(scp->session,SSH_FATAL, "scp status code %ud not valid", code); + scp->state=SSH_SCP_ERROR; + return SSH_ERROR; + } + return SSH_OK; +} + + /** @brief initializes the sending of a file to a scp in sink mode * @param filename Name of the file being sent. It should not contain any path indicator * @param size Exact size in bytes of the file being sent. -- cgit From 6a04b43a45896822732dedec1a4a2d972fbb9b80 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Sun, 23 Aug 2009 15:23:48 +0200 Subject: added ssh_scp_request_new,ssh_scp_request_struct --- libssh/scp.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libssh/scp.c') diff --git a/libssh/scp.c b/libssh/scp.c index 9035c44..e4cb348 100644 --- a/libssh/scp.c +++ b/libssh/scp.c @@ -266,3 +266,12 @@ int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len){ } return SSH_OK; } + +ssh_scp_request ssh_scp_request_new(void){ + ssh_scp_request r=malloc(sizeof(struct ssh_scp_request_struct)); + if(r==NULL) + return NULL; + ZERO_STRUCTP(r); + return r; +} + -- cgit