aboutsummaryrefslogtreecommitdiff
path: root/tests/test_exec.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-05-04 22:30:21 +0000
committerAndreas Schneider <mail@cynapses.org>2009-05-04 22:30:21 +0000
commitdc07d46ccaec73e65c7385c4f3a29da05d281ddd (patch)
tree4d392bc68fbbf0606a1b3635fd26ad6cb029bf99 /tests/test_exec.c
parent6c51183f0ebd48832b22e3e1ad587d2499dc65e9 (diff)
downloadlibssh-dc07d46ccaec73e65c7385c4f3a29da05d281ddd.tar.gz
libssh-dc07d46ccaec73e65c7385c4f3a29da05d281ddd.tar.xz
libssh-dc07d46ccaec73e65c7385c4f3a29da05d281ddd.zip
Add a exec test.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@713 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'tests/test_exec.c')
-rw-r--r--tests/test_exec.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test_exec.c b/tests/test_exec.c
new file mode 100644
index 0000000..1b2081d
--- /dev/null
+++ b/tests/test_exec.c
@@ -0,0 +1,62 @@
+/*
+This file is distributed in public domain. You can do whatever you want
+with its content.
+*/
+#include <libssh/libssh.h>
+#include <stdio.h>
+#include <string.h>
+#include "tests.h"
+
+void do_connect(SSH_SESSION *session) {
+ char buf[4096] = {0};
+ CHANNEL *channel;
+
+ int error = ssh_connect(session);
+ if (error != SSH_OK) {
+ fprintf(stderr,"Error at connection: %s\n", ssh_get_error(session));
+ return;
+ }
+ printf("Connected\n");
+
+ ssh_is_server_known(session);
+
+ error = authenticate(session);
+ if(error != SSH_AUTH_SUCCESS) {
+ fprintf(stderr,"Error at authentication: %s\n", ssh_get_error(session));
+ return;
+ }
+ printf("Authenticated\n");
+ channel = channel_new(session);
+ channel_open_session(channel);
+ printf("Execute 'ls' on the channel\n");
+ error = channel_request_exec(channel, "ls");
+ if(error != SSH_OK){
+ fprintf(stderr, "Error executing command: %s\n", ssh_get_error(session));
+ return;
+ }
+ printf("--------------------output----------------------\n");
+ while (channel_read(channel, buf, sizeof(buf), 0)) {
+ printf("%s", buf);
+ }
+ printf("\n");
+ printf("---------------------end------------------------\n");
+ channel_send_eof(channel);
+ fprintf(stderr, "Exit status: %d\n", channel_get_exit_status(channel));
+
+ printf("\nChannel test finished\n");
+ channel_close(channel);
+ channel_free(channel);
+}
+
+int main(int argc, char **argv){
+ SSH_OPTIONS *options=set_opts(argc, argv);
+ SSH_SESSION *session=ssh_new();
+ if(options==NULL){
+ return 1;
+ }
+ ssh_set_options(session,options);
+ do_connect(session);
+ ssh_disconnect(session);
+ ssh_finalize();
+ return 0;
+}