summaryrefslogtreecommitdiffstats
path: root/libssh/scp.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2009-08-23 14:57:03 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2009-08-23 14:57:03 +0200
commit049c62098cbd0d8efc342150a194fe72c9bdf6b0 (patch)
tree0964a8602a1168c66f62f150e13743919d49e4b8 /libssh/scp.c
parent6801959989defc3c360c5b7dc16c5bcc6a0f9c6b (diff)
downloadlibssh-049c62098cbd0d8efc342150a194fe72c9bdf6b0.tar.gz
libssh-049c62098cbd0d8efc342150a194fe72c9bdf6b0.tar.xz
libssh-049c62098cbd0d8efc342150a194fe72c9bdf6b0.zip
add ssh_scp_push_directory,ssh_scp_leave_directory
Not yet carefully tested
Diffstat (limited to 'libssh/scp.c')
-rw-r--r--libssh/scp.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/libssh/scp.c b/libssh/scp.c
index 06725e35..9035c440 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.