Skip to content

Commit 95b25f1

Browse files
sadyrovgouriano
authored andcommitted
Implemented SFTP API, tests and sample app. JIRA CXX-13855
git-svn-id: https://anonsvn.ncbi.nlm.nih.gov/repos/v1/trunk/c++@104380 78c7ea69-d796-4a43-9a09-de51944f1b03
1 parent 4a22a46 commit 95b25f1

21 files changed

+2134
-5
lines changed

include/common/ncbi_export.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,14 @@
15301530
# define NCBI_XXCONNECT2_EXPORT NCBI_DLL_IMPORT
15311531
#endif
15321532

1533+
/* Export specifier for library xconnsftp
1534+
*/
1535+
#ifdef NCBI_XCONNSFTP_EXPORTS
1536+
# define NCBI_XCONNSFTP_EXPORT NCBI_DLL_EXPORT
1537+
#else
1538+
# define NCBI_XCONNSFTP_EXPORT NCBI_DLL_IMPORT
1539+
#endif
1540+
15331541
/* Export specifier for library jaeger_tracer
15341542
*/
15351543
#ifdef NCBI_JAEGER_TRACER_EXPORTS

include/connect/ncbi_sftp.hpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#ifndef CONNECT__NCBI_SFTP__HPP
2+
#define CONNECT__NCBI_SFTP__HPP
3+
4+
/* $Id$
5+
* ===========================================================================
6+
*
7+
* PUBLIC DOMAIN NOTICE
8+
* National Center for Biotechnology Information
9+
*
10+
* This software/database is a "United States Government Work" under the
11+
* terms of the United States Copyright Act. It was written as part of
12+
* the author's official duties as a United States Government employee and
13+
* thus cannot be copyrighted. This software/database is freely available
14+
* to the public for use. The National Library of Medicine and the U.S.
15+
* Government have not placed any restriction on its use or reproduction.
16+
*
17+
* Although all reasonable efforts have been taken to ensure the accuracy
18+
* and reliability of the software and data, the NLM and the U.S.
19+
* Government do not and cannot warrant the performance or results that
20+
* may be obtained by using this software or data. The NLM and the U.S.
21+
* Government disclaim all warranties, express or implied, including
22+
* warranties of performance, merchantability or fitness for any particular
23+
* purpose.
24+
*
25+
* Please cite the author in any work or product based on this material.
26+
*
27+
* ===========================================================================
28+
*
29+
* Authors: Rafael Sadyrov
30+
*
31+
*/
32+
33+
#include <corelib/ncbistl.hpp>
34+
#include <corelib/ncbiexpt.hpp>
35+
#include <corelib/rwstream.hpp>
36+
37+
#include <memory>
38+
39+
#if defined(NCBI_THREADS) && defined(HAVE_LIBSSH)
40+
# define HAVE_SFTP 1
41+
#endif
42+
43+
#ifdef HAVE_SFTP
44+
45+
BEGIN_NCBI_SCOPE
46+
47+
48+
class NCBI_XCONNSFTP_EXPORT CSFTP_Exception : public CException
49+
{
50+
public:
51+
enum EErrCode {
52+
eInternalError,
53+
eInvalidArg,
54+
eAuthenticationError,
55+
};
56+
57+
virtual const char* GetErrCodeString() const override;
58+
59+
NCBI_EXCEPTION_DEFAULT(CSFTP_Exception, CException);
60+
};
61+
62+
63+
/// An SFTP client session.
64+
/// Required for SFTP client streams.
65+
///
66+
/// @sa CSFTP_Stream
67+
///
68+
class NCBI_XCONNSFTP_EXPORT CSFTP_Session
69+
{
70+
public:
71+
CSFTP_Session(const string& host,
72+
const string& password = {});
73+
74+
CSFTP_Session(const string& host,
75+
const string& user,
76+
const string& password = {});
77+
78+
private:
79+
shared_ptr<void> m_Impl;
80+
81+
friend class CSFTP_Stream;
82+
};
83+
84+
85+
/// An SFTP client stream.
86+
/// Supports most features of CConn_FtpStream,
87+
/// see <connect/ncbi_ftp_connector.h> for detailed explanations
88+
/// of supported features of the latter.
89+
///
90+
/// @sa CConn_FtpStream, FTP_CreateConnector
91+
///
92+
class NCBI_XCONNSFTP_EXPORT CSFTP_Stream : public CRWStream
93+
{
94+
public:
95+
CSFTP_Stream(CSFTP_Session session,
96+
string_view path = {});
97+
};
98+
99+
100+
END_NCBI_SCOPE
101+
102+
#endif
103+
#endif

src/connect/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ set(SRC_CXX
5656
)
5757

5858
NCBI_disable_pch()
59-
NCBI_add_library(connssl connect xxconnect xxconnect2 xconnect xthrserv)
59+
NCBI_add_library(connssl connect xxconnect xxconnect2 xconnect xthrserv xconnsftp)
6060
NCBI_add_subdirectory(services ext test)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# $Id$
2+
3+
NCBI_begin_lib(xconnsftp SHARED)
4+
NCBI_sources(ncbi_sftp)
5+
NCBI_add_definitions(NCBI_XCONNSFTP_EXPORTS)
6+
NCBI_uses_toolkit_libraries(xncbi)
7+
NCBI_requires(SSH)
8+
NCBI_project_watchers(sadyrovr)
9+
NCBI_end_lib()
10+

src/connect/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# - tests: "test/*.*"
1010
#################################
1111

12-
LIB_PROJ = connssl connect xxconnect xconnect xxconnect2 xthrserv
12+
LIB_PROJ = connssl connect xxconnect xconnect xxconnect2 xthrserv xconnsftp
1313
SUB_PROJ = services ext test
1414

1515
WATCHERS = lavr

src/connect/Makefile.xconnsftp.lib

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# $Id$
2+
3+
SRC = ncbi_sftp
4+
5+
LIB = xconnsftp
6+
7+
REQUIRES = LIBSSH
8+
9+
LIB_OR_DLL = both
10+
11+
CPPFLAGS = $(LIBSSH_INCLUDE) $(ORIG_CPPFLAGS)
12+
13+
LIBS = $(XCONNSFTP_LIBS) $(ORIG_LIBS)
14+
15+
WATCHERS = sadyrovr
16+
17+
USES_LIBRARIES = xncbi

src/connect/Makefile.xconnsftp.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# $Id$
2+
3+
XCONNSFTP_LIBS = $(LIBSSH_LIBS)
4+
XCONNSFTP_STATIC_LIBS = $(LIBSSH_STATIC_LIBS)

0 commit comments

Comments
 (0)