mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
tidy-up: example, tests
- drop unnecessary `WIN32`-specific branches. - add `static`. - sync header inclusion order. - sync some common code between examples/tests. - fix formatting/indentation. - fix some `checksrc` errors not caught by `checksrc`. Closes #936
This commit is contained in:
@ -12,17 +12,18 @@
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#ifdef WIN32
|
||||
# define write(f, b, c) write((f), (b), (unsigned int)(c))
|
||||
#define write(f, b, c) write((f), (b), (unsigned int)(c))
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
@ -36,12 +37,11 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
const char *keyfile1 = "~/.ssh/id_rsa.pub";
|
||||
const char *keyfile2 = "~/.ssh/id_rsa";
|
||||
const char *username = "username";
|
||||
const char *password = "password";
|
||||
const char *sftppath = "/tmp/TEST";
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
static const char *password = "password";
|
||||
static const char *sftppath = "/tmp/TEST";
|
||||
|
||||
static void kbd_callback(const char *name, int name_len,
|
||||
const char *instruction, int instruction_len,
|
||||
@ -91,7 +91,6 @@ static void kbd_callback(const char *name, int name_len,
|
||||
"Done. Sending keyboard-interactive responses to server now.\n");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uint32_t hostaddr;
|
||||
@ -122,7 +121,6 @@ int main(int argc, char *argv[])
|
||||
else {
|
||||
hostaddr = htonl(0x7F000001);
|
||||
}
|
||||
|
||||
if(argc > 2) {
|
||||
username = argv[2];
|
||||
}
|
||||
@ -148,8 +146,7 @@ int main(int argc, char *argv[])
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(22);
|
||||
sin.sin_addr.s_addr = hostaddr;
|
||||
if(connect(sock, (struct sockaddr*)(&sin),
|
||||
sizeof(struct sockaddr_in)) != 0) {
|
||||
if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) {
|
||||
fprintf(stderr, "failed to connect!\n");
|
||||
return -1;
|
||||
}
|
||||
@ -233,8 +230,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if(auth_pw & 4) {
|
||||
/* Or by public key */
|
||||
if(libssh2_userauth_publickey_fromfile(session, username, keyfile1,
|
||||
keyfile2, password)) {
|
||||
if(libssh2_userauth_publickey_fromfile(session, username,
|
||||
pubkey, privkey,
|
||||
password)) {
|
||||
fprintf(stderr, "\tAuthentication by public key failed!\n");
|
||||
goto shutdown;
|
||||
}
|
||||
@ -284,7 +282,7 @@ int main(int argc, char *argv[])
|
||||
libssh2_sftp_close(sftp_handle);
|
||||
libssh2_sftp_shutdown(sftp_session);
|
||||
|
||||
shutdown:
|
||||
shutdown:
|
||||
|
||||
libssh2_session_disconnect(session, "Normal Shutdown");
|
||||
libssh2_session_free(session);
|
||||
|
Reference in New Issue
Block a user