diff options
| author | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-08-09 22:51:03 +0200 |
|---|---|---|
| committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-08-09 22:51:03 +0200 |
| commit | f92e12c7b0950666fbbe8a8fabc7258a831dbab1 (patch) | |
| tree | 1761957f42b3138ee316aaf6833713a3820e2ab4 /libssh | |
| parent | e4da8b99feb82f4b86ec158b8056d24c3a2dde7d (diff) | |
| download | libssh-f92e12c7b0950666fbbe8a8fabc7258a831dbab1.tar.gz libssh-f92e12c7b0950666fbbe8a8fabc7258a831dbab1.tar.xz libssh-f92e12c7b0950666fbbe8a8fabc7258a831dbab1.zip | |
ssh_scp_push_file and ssh_scp_write
still needs tests
Diffstat (limited to 'libssh')
| -rw-r--r-- | libssh/libssh.def | 2 | ||||
| -rw-r--r-- | libssh/libssh.map | 6 | ||||
| -rw-r--r-- | libssh/scp.c | 52 |
3 files changed, 58 insertions, 2 deletions
diff --git a/libssh/libssh.def b/libssh/libssh.def index b2848ce..7b0ea79 100644 --- a/libssh/libssh.def +++ b/libssh/libssh.def @@ -171,6 +171,8 @@ ssh_scp_close ssh_scp_free ssh_scp_init ssh_scp_new +ssh_scp_push_file +ssh_scp_write ssh_select ssh_service_request ssh_set_blocking diff --git a/libssh/libssh.map b/libssh/libssh.map index b3e2206..e689c2b 100644 --- a/libssh/libssh.map +++ b/libssh/libssh.map @@ -188,10 +188,12 @@ SSH_0.4 { channel_write_stderr; channel_request_x11; channel_accept_x11; - ssh_scp_new; + ssh_scp_close; ssh_scp_free; ssh_scp_init; - ssh_scp_close; + ssh_scp_new; + ssh_scp_push_file + ssh_scp_write sftp_extensions_get_count; sftp_extensions_get_data; sftp_extensions_get_name; diff --git a/libssh/scp.c b/libssh/scp.c index 84db3b5..b2fc2c9 100644 --- a/libssh/scp.c +++ b/libssh/scp.c @@ -92,3 +92,55 @@ void ssh_scp_free(ssh_scp scp){ SAFE_FREE(scp->location); SAFE_FREE(scp); } + +/** @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. + * @param perms Text form of the unix permissions for the new file, e.g. "0644" + * @returns SSH_OK if the file is ready to be sent. + * @returns SSH_ERROR if an error happened. + */ +int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, const char *perms){ + char buffer[1024]; + int r; + u_int8_t code; + snprintf(buffer,sizeof(buffer),"C%s %ld %s\n",perms, size, filename); + r=channel_write(scp->channel,buffer,strlen(buffer)); + if(r==SSH_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); + return SSH_ERROR; + } + scp->filelen = size; + scp->processed = 0; + return SSH_OK; +} + +/** @brief Write into a remote scp file + * @param buffer the buffer to write + * @param len the number of bytes to write + * @returns SSH_OK the write was successful + * @returns SSH_ERROR an error happened while writing + */ +int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len){ + int w,r; + u_int8_t code; + if(scp->processed + len > scp->filelen) + len = scp->filelen - scp->processed; + w=channel_write(scp->channel,buffer,len); + if(w != SSH_ERROR) + scp->processed += w; + else + return w; + if(scp->processed == scp->filelen) { + 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); + return SSH_ERROR; + } + scp->processed=scp->filelen=0; + } + return SSH_OK; +} |
