New sample that writes a lot of data on channel

This commit is contained in:
Aris Adamantiadis 2010-05-17 20:03:44 +02:00
parent 2c014256f7
commit 08bc076a0a
3 changed files with 61 additions and 4 deletions

View File

@ -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(

View File

@ -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));
}
}

54
examples/senddata.c Normal file
View File

@ -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;
}