From: Vadim Zeitlin Date: Thu, 17 Jun 2010 22:30:31 +0000 (+0000) Subject: Allow specifying non default port for wxFTP connections. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/9655ec028f79daba0402d0880658a7e1e59c999d Allow specifying non default port for wxFTP connections. Add a wxFTP::Connect() overload taking a port number. Also specify the default port (21) explicitly if resolving "ftp" service name failed. Closes #12145. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64621 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/protocol/ftp.h b/include/wx/protocol/ftp.h index bfe39ce017..186e21ffdd 100644 --- a/include/wx/protocol/ftp.h +++ b/include/wx/protocol/ftp.h @@ -35,8 +35,9 @@ public: virtual ~wxFTP(); // Connecting and disconnecting - bool Connect(const wxSockAddress& addr, bool wait = true); - bool Connect(const wxString& host); + virtual bool Connect(const wxSockAddress& addr, bool wait = true); + virtual bool Connect(const wxString& host) { return Connect(host, 0); } + virtual bool Connect(const wxString& host, unsigned short port); // disconnect virtual bool Close(); diff --git a/interface/wx/protocol/ftp.h b/interface/wx/protocol/ftp.h index 364e5e434d..b03ce1a163 100644 --- a/interface/wx/protocol/ftp.h +++ b/interface/wx/protocol/ftp.h @@ -112,6 +112,22 @@ public: + //@{ + /** + Connect to the FTP server to default port (21) of the specified @a host. + */ + virtual bool Connect(const wxString& host); + + /** + Connect to the FTP server to any port of the specified @a host. + By default (@a port = 0), connection is made to default FTP port (21) + of the specified @a host. + + @since 2.9.1 + */ + virtual bool Connect(const wxString& host, unsigned short port); + //@} + /** @name Functions for managing the FTP connection */ diff --git a/src/common/ftp.cpp b/src/common/ftp.cpp index b1761ba387..218fa45784 100644 --- a/src/common/ftp.cpp +++ b/src/common/ftp.cpp @@ -155,11 +155,15 @@ bool wxFTP::Connect(const wxSockAddress& addr, bool WXUNUSED(wait)) return true; } -bool wxFTP::Connect(const wxString& host) +bool wxFTP::Connect(const wxString& host, unsigned short port) { wxIPV4address addr; addr.Hostname(host); - addr.Service(wxT("ftp")); + + if ( port ) + addr.Service(port); + else if (!addr.Service(wxT("ftp"))) + addr.Service(21); return Connect(addr); }