New sample that writes a lot of data on channel
Этот коммит содержится в:
родитель
2c014256f7
Коммит
08bc076a0a
@ -15,12 +15,15 @@ add_executable(libssh_scp libssh_scp.c ${examples_SRCS})
|
|||||||
add_executable(scp_download scp_download.c ${examples_SRCS})
|
add_executable(scp_download scp_download.c ${examples_SRCS})
|
||||||
add_executable(samplessh sample.c ${examples_SRCS})
|
add_executable(samplessh sample.c ${examples_SRCS})
|
||||||
add_executable(exec exec.c ${examples_SRCS})
|
add_executable(exec exec.c ${examples_SRCS})
|
||||||
|
add_executable(senddata senddata.c ${examples_SRCS})
|
||||||
|
|
||||||
add_executable(libsshpp libsshpp.cpp)
|
add_executable(libsshpp libsshpp.cpp)
|
||||||
|
|
||||||
target_link_libraries(libssh_scp ${LIBSSH_SHARED_LIBRARY})
|
target_link_libraries(libssh_scp ${LIBSSH_SHARED_LIBRARY})
|
||||||
target_link_libraries(scp_download ${LIBSSH_SHARED_LIBRARY})
|
target_link_libraries(scp_download ${LIBSSH_SHARED_LIBRARY})
|
||||||
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
|
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
|
||||||
target_link_libraries(exec ${LIBSSH_SHARED_LIBRARY})
|
target_link_libraries(exec ${LIBSSH_SHARED_LIBRARY})
|
||||||
|
target_link_libraries(senddata ${LIBSSH_SHARED_LIBRARY})
|
||||||
target_link_libraries(libsshpp ${LIBSSH_SHARED_LIBRARY})
|
target_link_libraries(libsshpp ${LIBSSH_SHARED_LIBRARY})
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
@ -29,7 +29,7 @@ clients must be made or how a client should react.
|
|||||||
|
|
||||||
int verbosity;
|
int verbosity;
|
||||||
char *destination;
|
char *destination;
|
||||||
|
#define DATALEN 65536
|
||||||
static void do_sftp(ssh_session session){
|
static void do_sftp(ssh_session session){
|
||||||
sftp_session sftp=sftp_new(session);
|
sftp_session sftp=sftp_new(session);
|
||||||
sftp_dir dir;
|
sftp_dir dir;
|
||||||
@ -40,7 +40,7 @@ static void do_sftp(ssh_session session){
|
|||||||
sftp_file to;
|
sftp_file to;
|
||||||
int len=1;
|
int len=1;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char data[8000]={0};
|
char data[DATALEN]={0};
|
||||||
char *lnk;
|
char *lnk;
|
||||||
|
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
@ -202,9 +202,9 @@ static void do_sftp(ssh_session session){
|
|||||||
printf("fichiers ferm\n");
|
printf("fichiers ferm\n");
|
||||||
to=sftp_open(sftp,"/tmp/grosfichier",O_WRONLY|O_CREAT, 0644);
|
to=sftp_open(sftp,"/tmp/grosfichier",O_WRONLY|O_CREAT, 0644);
|
||||||
for(i=0;i<1000;++i){
|
for(i=0;i<1000;++i){
|
||||||
len=sftp_write(to,data,8000);
|
len=sftp_write(to,data,DATALEN);
|
||||||
printf("wrote %d bytes\n",len);
|
printf("wrote %d bytes\n",len);
|
||||||
if(len != 8000){
|
if(len != DATALEN){
|
||||||
printf("chunk %d : %d (%s)\n",i,len,ssh_get_error(session));
|
printf("chunk %d : %d (%s)\n",i,len,ssh_get_error(session));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
54
examples/senddata.c
Обычный файл
54
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;
|
||||||
|
}
|
Загрузка…
x
Ссылка в новой задаче
Block a user