1//
2// FTPSStreamFactory.h
3//
4// Library: Net
5// Package: FTP
6// Module: FTPSStreamFactory
7//
8// Definition of the FTPSStreamFactory class.
9//
10// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Net_FTPSStreamFactory_INCLUDED
18#define Net_FTPSStreamFactory_INCLUDED
19
20
21#include "Poco/Net/NetSSL.h"
22#include "Poco/Net/HTTPSession.h"
23#include "Poco/URIStreamFactory.h"
24#include "Poco/Net/FTPStreamFactory.h"
25#include "Poco/Net/FTPPasswordProvider.h"
26
27namespace Poco {
28namespace Net {
29
30
31class NetSSL_API FTPSStreamFactory: public Poco::URIStreamFactory
32 /// An implementation of the URIStreamFactory interface
33 /// that handles File Transfer Protocol (ftp) URIs.
34 ///
35 /// The URI's path may end with an optional type specification
36 /// in the form (;type=<typecode>), where <typecode> is
37 /// one of a, i or d. If type=a, the file identified by the path
38 /// is transferred in ASCII (text) mode. If type=i, the file
39 /// is transferred in Image (binary) mode. If type=d, a directory
40 /// listing (in NLST format) is returned. This corresponds with
41 /// the FTP URL format specified in RFC 1738.
42 ///
43 /// If the URI does not contain a username and password, the
44 /// username "anonymous" and the password "
45{
46public:
47 FTPSStreamFactory();
48 /// Creates the FTPSStreamFactory.
49
50 ~FTPSStreamFactory();
51 /// Destroys the FTPSStreamFactory.
52
53 std::istream* open(const Poco::URI& uri);
54 /// Creates and opens a HTTP stream for the given URI.
55 /// The URI must be a ftp://... URI.
56 ///
57 /// Throws a NetException if anything goes wrong.
58
59 static void setAnonymousPassword(const std::string& password);
60 /// Sets the password used for anonymous FTP.
61 ///
62 /// WARNING: Setting the anonymous password is not
63 /// thread-safe, so it's best to call this method
64 /// during application initialization, before the
65 /// FTPSStreamFactory is used for the first time.
66
67 static const std::string& getAnonymousPassword();
68 /// Returns the password used for anonymous FTP.
69
70 static void setPasswordProvider(FTPPasswordProvider* pProvider);
71 /// Sets the FTPPasswordProvider. If NULL is given,
72 /// no password provider is used.
73 ///
74 /// WARNING: Setting the password provider is not
75 /// thread-safe, so it's best to call this method
76 /// during application initialization, before the
77 /// FTPSStreamFactory is used for the first time.
78
79 static FTPPasswordProvider* getPasswordProvider();
80 /// Returns the FTPPasswordProvider currently in use,
81 /// or NULL if no one has been set.
82
83 static void registerFactory();
84 /// Registers the FTPSStreamFactory with the
85 /// default URIStreamOpener instance.
86
87 static void unregisterFactory();
88 /// Unregisters the FTPSStreamFactory with the
89 /// default URIStreamOpener instance.
90
91protected:
92 static void splitUserInfo(const std::string& userInfo, std::string& username, std::string& password);
93 static void getUserInfo(const Poco::URI& uri, std::string& username, std::string& password);
94 static void getPathAndType(const Poco::URI& uri, std::string& path, char& type);
95
96private:
97 static std::string _anonymousPassword;
98 static FTPPasswordProvider* _pPasswordProvider;
99};
100
101
102} } // namespace Poco::Net
103
104
105#endif // Net_FTPSStreamFactory_INCLUDED