From 92c75854fb6252a5da6a567b018ecf2ba1912795 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 8 Feb 2007 14:44:32 +0000 Subject: [PATCH] Guenter Knauf added support for another IP and I changed the order of the arguments and updated some comments. --- example/simple/sftp.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/example/simple/sftp.c b/example/simple/sftp.c index c9aa7562..8c291385 100644 --- a/example/simple/sftp.c +++ b/example/simple/sftp.c @@ -1,7 +1,12 @@ /* - * $Id: sftp.c,v 1.2 2007/02/02 16:21:20 bagder Exp $ + * $Id: sftp.c,v 1.3 2007/02/08 14:44:32 bagder Exp $ * * Sample showing how to do SFTP transfers. + * + * 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: + * + * "sftp 192.168.0.1 user password /tmp/secrets" */ #include @@ -23,6 +28,7 @@ int main(int argc, char *argv[]) { + unsigned long hostaddr; int sock, i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; @@ -40,15 +46,30 @@ int main(int argc, char *argv[]) WSAStartup(WINSOCK_VERSION, &wsadata); #endif - /* Ultra basic "connect to port 22 on localhost" - * Your code is responsible for creating the socket establishing the - * connection + if (argc > 1) { + hostaddr = inet_addr(argv[1]); + } else { + hostaddr = htonl(0x7F000001); + } + + if(argc > 2) { + username = argv[2]; + } + if(argc > 3) { + password = argv[3]; + } + if(argc > 4) { + sftppath = argv[4]; + } + /* + * The application code is responsible for creating the socket + * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); sin.sin_family = AF_INET; sin.sin_port = htons(22); - sin.sin_addr.s_addr = htonl(0x7F000001); + sin.sin_addr.s_addr = hostaddr; if (connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) { fprintf(stderr, "failed to connect!\n"); @@ -82,16 +103,6 @@ int main(int argc, char *argv[]) } printf("\n"); - if(argc > 1) { - username = argv[1]; - } - if(argc > 2) { - password = argv[2]; - } - if(argc > 3) { - sftppath = argv[3]; - } - if (auth_pw) { /* We could authenticate via password */ if (libssh2_userauth_password(session, username, password)) {