NCL Composer  0.1.5
 All Classes Functions Variables Pages
SimpleSSHClient.h
1 /* Copyright (c) 2011 Telemidia/PUC-Rio.
2  * All rights reserved. This program and the accompanying materials
3  * are made available under the terms of the Eclipse Public License v1.0
4  * which accompanies this distribution, and is available at
5  * http://www.eclipse.org/legal/epl-v10.html
6  *
7  * Contributors:
8  * Telemidia/PUC-Rio - initial API and implementation
9  */
10 #ifndef SIMPLESSHCLIENT_H
11 #define SIMPLESSHCLIENT_H
12 
13 extern "C" {
14 // #include "libssh2_config.h"
15 #include <libssh2.h>
16 #include <libssh2_sftp.h>
17 
18 #ifdef WIN32
19 #include <winsock2.h>
20 #else
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <unistd.h>
24 #include <arpa/inet.h>
25 #endif
26 
27 #include <sys/time.h>
28 #include <sys/types.h>
29 #include <stdlib.h>
30 #include <fcntl.h>
31 #include <errno.h>
32 #include <stdio.h>
33 #include <ctype.h>
34 }
35 
36 #include <string>
37 using namespace std;
38 
39 #include <QMutex>
40 
41 //\todo A better way to send error report than fprintf
43 {
44 private:
45  string username;
46  string password;
47  string hostip;
48  string sftp_path;
49  string sftp_file;
50  static int libssh2_init_rc; /* Keeps the value returned by lissh2_init */
51 
52  int sock;
53 
54  LIBSSH2_SESSION *session;
55  LIBSSH2_SFTP *sftp_session;
56 
57 public:
61  SimpleSSHClient(const char *username, const char *password,
62  const char *hostip, const char *remotepath);
63 
68  static int init();
69 
73  static void exit();
74 
78  int doConnect(); // I do not call connect because it conflicts with win32
79  // connect.
83  void doDisconnect(); // For consistency I also call this doDisconnect.
84 
88  int sftp_copy_file(const char *localfile, const char* destpath);
89 
93  int exec_cmd(const char *command);
94 
95  static int waitsocket(int socket_fd, LIBSSH2_SESSION *session);
96 };
97 
98 #endif // SIMPLESSHCLIENT_H