diff --git a/example/simple/Makefile.am b/example/simple/Makefile.am index 93f468f..5826b23 100644 --- a/example/simple/Makefile.am +++ b/example/simple/Makefile.am @@ -9,7 +9,7 @@ noinst_PROGRAMS = ssh2 \ sftp_RW_nonblock \ sftpdir sftpdir_nonblock -INCLUDES = -I$(top_srcdir)/include +INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/src LDADD = $(top_builddir)/src/libssh2.la ssh2_SOURCES = ssh2.c diff --git a/example/simple/scp.c b/example/simple/scp.c index 08cc950..e3c0910 100644 --- a/example/simple/scp.c +++ b/example/simple/scp.c @@ -1,10 +1,11 @@ /* - * $Id: scp.c,v 1.5 2007/04/26 22:59:29 gknauf Exp $ + * $Id: scp.c,v 1.6 2007/04/26 23:59:14 gknauf Exp $ * * Sample showing how to do a simple SCP transfer. */ #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/scp_nonblock.c b/example/simple/scp_nonblock.c index f319f4a..0753ad6 100644 --- a/example/simple/scp_nonblock.c +++ b/example/simple/scp_nonblock.c @@ -1,10 +1,11 @@ /* - * $Id: scp_nonblock.c,v 1.2 2007/04/26 22:59:29 gknauf Exp $ + * $Id: scp_nonblock.c,v 1.3 2007/04/26 23:59:14 gknauf Exp $ * * Sample showing how to do SCP transfers in a non-blocking manner. */ #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/sftp.c b/example/simple/sftp.c index 9ce21c6..eba4042 100644 --- a/example/simple/sftp.c +++ b/example/simple/sftp.c @@ -1,5 +1,5 @@ /* - * $Id: sftp.c,v 1.6 2007/04/26 22:59:29 gknauf Exp $ + * $Id: sftp.c,v 1.7 2007/04/26 23:59:14 gknauf Exp $ * * Sample showing how to do SFTP transfers. * @@ -11,6 +11,7 @@ #include #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/sftp_RW_nonblock.c b/example/simple/sftp_RW_nonblock.c index 82d4ef2..d76f3a1 100644 --- a/example/simple/sftp_RW_nonblock.c +++ b/example/simple/sftp_RW_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_RW_nonblock.c,v 1.2 2007/04/26 22:59:29 gknauf Exp $ + * $Id: sftp_RW_nonblock.c,v 1.3 2007/04/26 23:59:15 gknauf Exp $ * * Sample showing how to do SFTP transfers in a non-blocking manner. * @@ -11,6 +11,7 @@ #include #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/sftp_mkdir.c b/example/simple/sftp_mkdir.c index 4c14bed..d83ed43 100644 --- a/example/simple/sftp_mkdir.c +++ b/example/simple/sftp_mkdir.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_mkdir.c,v 1.2 2007/04/26 22:59:29 gknauf Exp $ + * $Id: sftp_mkdir.c,v 1.3 2007/04/26 23:59:15 gknauf Exp $ * * Sample showing how to do SFTP mkdir * @@ -11,6 +11,7 @@ #include #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/sftp_mkdir_nonblock.c b/example/simple/sftp_mkdir_nonblock.c index ee2d3fe..d62d606 100644 --- a/example/simple/sftp_mkdir_nonblock.c +++ b/example/simple/sftp_mkdir_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_mkdir_nonblock.c,v 1.2 2007/04/26 22:59:29 gknauf Exp $ + * $Id: sftp_mkdir_nonblock.c,v 1.3 2007/04/26 23:59:15 gknauf Exp $ * * Sample showing how to do SFTP non-blocking mkdir. * @@ -11,6 +11,7 @@ #include #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/sftp_nonblock.c b/example/simple/sftp_nonblock.c index e40b675..289ef2e 100644 --- a/example/simple/sftp_nonblock.c +++ b/example/simple/sftp_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_nonblock.c,v 1.6 2007/04/26 22:59:29 gknauf Exp $ + * $Id: sftp_nonblock.c,v 1.7 2007/04/26 23:59:15 gknauf Exp $ * * Sample showing how to do SFTP non-blocking transfers. * @@ -11,6 +11,7 @@ #include #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/sftp_write.c b/example/simple/sftp_write.c index a9e20b1..6e8dd5c 100644 --- a/example/simple/sftp_write.c +++ b/example/simple/sftp_write.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_write.c,v 1.2 2007/04/26 22:59:29 gknauf Exp $ + * $Id: sftp_write.c,v 1.3 2007/04/26 23:59:15 gknauf Exp $ * * Sample showing how to do SFTP write transfers. * @@ -11,6 +11,7 @@ #include #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/sftp_write_nonblock.c b/example/simple/sftp_write_nonblock.c index 3368c18..1b20b84 100644 --- a/example/simple/sftp_write_nonblock.c +++ b/example/simple/sftp_write_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_write_nonblock.c,v 1.2 2007/04/26 22:59:29 gknauf Exp $ + * $Id: sftp_write_nonblock.c,v 1.3 2007/04/26 23:59:15 gknauf Exp $ * * Sample showing how to do SFTP non-blocking write transfers. * @@ -11,6 +11,7 @@ #include #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/sftpdir.c b/example/simple/sftpdir.c index b1dd949..287df26 100644 --- a/example/simple/sftpdir.c +++ b/example/simple/sftpdir.c @@ -1,5 +1,5 @@ /* - * $Id: sftpdir.c,v 1.3 2007/04/26 22:59:29 gknauf Exp $ + * $Id: sftpdir.c,v 1.4 2007/04/26 23:59:15 gknauf Exp $ * * Sample doing an SFTP directory listing. * @@ -11,6 +11,7 @@ #include #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/sftpdir_nonblock.c b/example/simple/sftpdir_nonblock.c index 761f862..e577bff 100644 --- a/example/simple/sftpdir_nonblock.c +++ b/example/simple/sftpdir_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftpdir_nonblock.c,v 1.3 2007/04/26 22:59:29 gknauf Exp $ + * $Id: sftpdir_nonblock.c,v 1.4 2007/04/26 23:59:15 gknauf Exp $ * * Sample doing an SFTP directory listing. * @@ -11,6 +11,7 @@ #include #include +#include #ifdef HAVE_WINSOCK2_H # include diff --git a/example/simple/ssh2.c b/example/simple/ssh2.c index 0b26215..5f2875e 100644 --- a/example/simple/ssh2.c +++ b/example/simple/ssh2.c @@ -1,4 +1,17 @@ -#include "libssh2.h" +/* + * $Id: ssh2.c,v 1.3 2007/04/26 23:59:15 gknauf Exp $ + * + * Sample showing how to do SSH2 connect. + * + * The sample code has default values for host name, user name, password + * and path to copy, but you can specify them on the command line like: + * + * "ssh2 host user password" + */ + +#include +#include +#include #ifdef HAVE_WINSOCK2_H # include @@ -21,6 +34,7 @@ int main(int argc, char *argv[]) { + unsigned long hostaddr; int sock, i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; @@ -34,6 +48,19 @@ int main(int argc, char *argv[]) WSAStartup(WINSOCK_VERSION, &wsadata); #endif + if (argc > 1) { + hostaddr = inet_addr(argv[1]); + } else { + hostaddr = htonl(0x7F000001); + } + + if(argc > 2) { + username = argv[2]; + } + if(argc > 3) { + password = argv[3]; + } + /* Ultra basic "connect to port 22 on localhost" * Your code is responsible for creating the socket establishing the connection */ @@ -43,8 +70,9 @@ int main(int argc, char *argv[]) #endif sin.sin_family = AF_INET; sin.sin_port = htons(22); - sin.sin_addr.s_addr = htonl(0x7F000001); - if (connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) { + sin.sin_addr.s_addr = hostaddr; + if (connect(sock, (struct sockaddr*)(&sin), + sizeof(struct sockaddr_in)) != 0) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -69,13 +97,6 @@ int main(int argc, char *argv[]) } printf("\n"); - if(argc > 1) { - username = argv[1]; - } - if(argc > 2) { - password = argv[2]; - } - if (auth_pw) { /* We could authenticate via password */ if (libssh2_userauth_password(session, username, password)) {