aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-05-17 20:03:44 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2010-05-17 20:08:10 +0200
commit08bc076a0af55bb9fc6dfc48db2a0efdb35223a3 (patch)
tree67da4cc95ad2a78902d748e90d8dfb34a3867475 /examples
parent2c014256f7f7490d7b45c7b452b8711b5c8e938f (diff)
downloadlibssh-08bc076a0af55bb9fc6dfc48db2a0efdb35223a3.tar.gz
libssh-08bc076a0af55bb9fc6dfc48db2a0efdb35223a3.tar.xz
libssh-08bc076a0af55bb9fc6dfc48db2a0efdb35223a3.zip
New sample that writes a lot of data on channel
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt3
-rw-r--r--examples/samplesftp.c8
-rw-r--r--examples/senddata.c54
3 files changed, 61 insertions, 4 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 94d89499..b912df56 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -15,12 +15,15 @@ add_executable(libssh_scp libssh_scp.c ${examples_SRCS})
add_executable(scp_download scp_download.c ${examples_SRCS})
add_executable(samplessh sample.c ${examples_SRCS})
add_executable(exec exec.c ${examples_SRCS})
+add_executable(senddata senddata.c ${examples_SRCS})
+
add_executable(libsshpp libsshpp.cpp)
target_link_libraries(libssh_scp ${LIBSSH_SHARED_LIBRARY})
target_link_libraries(scp_download ${LIBSSH_SHARED_LIBRARY})
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
target_link_libraries(exec ${LIBSSH_SHARED_LIBRARY})
+target_link_libraries(senddata ${LIBSSH_SHARED_LIBRARY})
target_link_libraries(libsshpp ${LIBSSH_SHARED_LIBRARY})
include_directories(
diff --git a/examples/samplesftp.c b/examples/samplesftp.c
index a7428a5b..f25e36c3 100644
--- a/examples/samplesftp.c
+++ b/examples/samplesftp.c
@@ -29,7 +29,7 @@ clients must be made or how a client should react.
int verbosity;
char *destination;
-
+#define DATALEN 65536
static void do_sftp(ssh_session session){
sftp_session sftp=sftp_new(session);
sftp_dir dir;
@@ -40,7 +40,7 @@ static void do_sftp(ssh_session session){
sftp_file to;
int len=1;
unsigned int i;
- char data[8000]={0};
+ char data[DATALEN]={0};
char *lnk;
unsigned int count;
@@ -202,9 +202,9 @@ static void do_sftp(ssh_session session){
printf("fichiers ferm\n");
to=sftp_open(sftp,"/tmp/grosfichier",O_WRONLY|O_CREAT, 0644);
for(i=0;i<1000;++i){
- len=sftp_write(to,data,8000);
+ len=sftp_write(to,data,DATALEN);
printf("wrote %d bytes\n",len);
- if(len != 8000){
+ if(len != DATALEN){
printf("chunk %d : %d (%s)\n",i,len,ssh_get_error(session));
}
}
diff --git a/examples/senddata.c b/examples/senddata.c
new file mode 100644
index 00000000..9de76387
--- /dev/null
+++ b/examples/senddata.c
@@ -0,0 +1,54 @@
+#include <stdio.h>
+
+#include <libssh/libssh.h>
+#include "examples_common.h"
+
+int main(void) {
+ ssh_session session;
+ ssh_channel channel;
+ char buffer[1024*1024];
+ int rc;
+
+ session = connect_ssh("172.16.104.134", NULL, 0);
+ if (session == NULL) {
+ return 1;
+ }
+
+ channel = ssh_channel_new(session);;
+ if (channel == NULL) {
+ ssh_disconnect(session);
+ return 1;
+ }
+
+ rc = ssh_channel_open_session(channel);
+ if (rc < 0) {
+ ssh_channel_close(channel);
+ ssh_disconnect(session);
+ return 1;
+ }
+
+ rc = ssh_channel_request_exec(channel, "cat > /dev/null");
+ if (rc < 0) {
+ ssh_channel_close(channel);
+ ssh_disconnect(session);
+ return 1;
+ }
+
+
+ while ((rc = ssh_channel_write(channel, buffer, sizeof(buffer))) > 0) {
+ }
+
+ if (rc < 0) {
+ printf("error : %s\n",ssh_get_error(session));
+ ssh_channel_close(channel);
+ ssh_disconnect(session);
+ return 1;
+ }
+
+ ssh_channel_send_eof(channel);
+ ssh_channel_close(channel);
+
+ ssh_disconnect(session);
+
+ return 0;
+}