Add passive mode option to TMS upload.
authorCarl Hetherington <cth@carlh.net>
Tue, 1 Nov 2022 19:58:10 +0000 (20:58 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 2 Nov 2022 00:17:13 +0000 (01:17 +0100)
Disabling this fixes TMS upload with some FTP servers
(reported on a Synology NAS).

src/lib/config.cc
src/lib/config.h
src/lib/curl_uploader.cc
src/wx/full_config_dialog.cc

index 81daff5b6bed8e2eee19ee743ec56391ab0f7489..6984c406440d46ae4d795eae9319d6b3f1e2c3e1 100644 (file)
@@ -94,6 +94,7 @@ Config::set_defaults ()
        _servers.clear ();
        _only_servers_encode = false;
        _tms_protocol = FileTransferProtocol::SCP;
+       _tms_passive = true;
        _tms_ip = "";
        _tms_path = ".";
        _tms_user = "";
@@ -325,6 +326,7 @@ try
 
        _only_servers_encode = f.optional_bool_child ("OnlyServersEncode").get_value_or (false);
        _tms_protocol = static_cast<FileTransferProtocol>(f.optional_number_child<int>("TMSProtocol").get_value_or(static_cast<int>(FileTransferProtocol::SCP)));
+       _tms_passive = f.optional_bool_child("TMSPassive").get_value_or(true);
        _tms_ip = f.string_child ("TMSIP");
        _tms_path = f.string_child ("TMSPath");
        _tms_user = f.string_child ("TMSUser");
@@ -719,6 +721,8 @@ Config::write_config () const
        root->add_child("OnlyServersEncode")->add_child_text (_only_servers_encode ? "1" : "0");
        /* [XML] TMSProtocol Protocol to use to copy files to a TMS; 0 to use SCP, 1 for FTP. */
        root->add_child("TMSProtocol")->add_child_text (raw_convert<string> (static_cast<int> (_tms_protocol)));
+       /* [XML] TMSPassive True to use PASV mode with TMS FTP connections. */
+       root->add_child("TMSPassive")->add_child_text(_tms_passive ? "1" : "0");
        /* [XML] TMSIP IP address of TMS. */
        root->add_child("TMSIP")->add_child_text (_tms_ip);
        /* [XML] TMSPath Path on the TMS to copy files to. */
index 1a11b4a411635e1b550cdb5e78d32e36121843db..9e84a120b822755bf667e32b024ba16374bc9537 100644 (file)
@@ -130,6 +130,10 @@ public:
                return _tms_protocol;
        }
 
+       bool tms_passive() const {
+               return _tms_passive;
+       }
+
        /** @return The IP address of a TMS that we can copy DCPs to */
        std::string tms_ip () const {
                return _tms_ip;
@@ -629,6 +633,10 @@ public:
                maybe_set (_tms_protocol, p);
        }
 
+       void set_tms_passive(bool passive) {
+               maybe_set(_tms_passive, passive);
+       }
+
        /** @param i IP address of a TMS that we can copy DCPs to */
        void set_tms_ip (std::string i) {
                maybe_set (_tms_ip, i);
@@ -1256,6 +1264,7 @@ private:
        std::vector<std::string> _servers;
        bool _only_servers_encode;
        FileTransferProtocol _tms_protocol;
+       bool _tms_passive;
        /** The IP address of a TMS that we can copy DCPs to */
        std::string _tms_ip;
        /** The path on a TMS that we should write DCPs to */
index 6fe7aba145c40ecfa2fd91f2ae035dee0d6f0a5b..9416a17fb800cdb6b95f0dc96977adc4135cfcdb 100644 (file)
@@ -58,6 +58,9 @@ CurlUploader::CurlUploader (function<void (string)> set_status, function<void (f
        curl_easy_setopt (_curl, CURLOPT_READDATA, this);
        curl_easy_setopt (_curl, CURLOPT_USERNAME, Config::instance()->tms_user().c_str());
        curl_easy_setopt (_curl, CURLOPT_PASSWORD, Config::instance()->tms_password().c_str());
+       if (!Config::instance()->tms_passive()) {
+               curl_easy_setopt(_curl, CURLOPT_FTPPORT, "-");
+       }
 }
 
 
index 1aeacd3cacd9ae05df0aabcb7ebe9b1eb84acd0b..1eb87d93e70b05f419b0b65cb0f88dcad46c7112 100644 (file)
@@ -696,6 +696,10 @@ private:
                _tms_protocol = new wxChoice (_panel, wxID_ANY);
                table->Add (_tms_protocol, 1, wxEXPAND);
 
+               _tms_passive = new CheckBox(_panel, _("Passive mode"));
+               table->Add(_tms_passive, 1, wxEXPAND);
+               table->AddSpacer(0);
+
                add_label_to_sizer (table, _panel, _("IP address"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
                _tms_ip = new wxTextCtrl (_panel, wxID_ANY);
                table->Add (_tms_ip, 1, wxEXPAND);
@@ -717,6 +721,8 @@ private:
 
                _upload->Bind (wxEVT_CHECKBOX, boost::bind(&TMSPage::upload_changed, this));
                _tms_protocol->Bind (wxEVT_CHOICE, boost::bind (&TMSPage::tms_protocol_changed, this));
+               _tms_passive->bind(&TMSPage::tms_passive_changed, this);
+
                _tms_ip->Bind (wxEVT_TEXT, boost::bind (&TMSPage::tms_ip_changed, this));
                _tms_path->Bind (wxEVT_TEXT, boost::bind (&TMSPage::tms_path_changed, this));
                _tms_user->Bind (wxEVT_TEXT, boost::bind (&TMSPage::tms_user_changed, this));
@@ -729,10 +735,13 @@ private:
 
                checked_set (_upload, config->upload_after_make_dcp());
                checked_set (_tms_protocol, static_cast<int>(config->tms_protocol()));
+               checked_set(_tms_passive, config->tms_protocol() == FileTransferProtocol::FTP && config->tms_passive());
                checked_set (_tms_ip, config->tms_ip ());
                checked_set (_tms_path, config->tms_path ());
                checked_set (_tms_user, config->tms_user ());
                checked_set (_tms_password, config->tms_password ());
+
+               _tms_passive->Enable(config->tms_protocol() == FileTransferProtocol::FTP);
        }
 
        void upload_changed ()
@@ -745,6 +754,11 @@ private:
                Config::instance()->set_tms_protocol(static_cast<FileTransferProtocol>(_tms_protocol->GetSelection()));
        }
 
+       void tms_passive_changed()
+       {
+               Config::instance()->set_tms_passive(_tms_passive->get());
+       }
+
        void tms_ip_changed ()
        {
                Config::instance()->set_tms_ip (wx_to_std (_tms_ip->GetValue ()));
@@ -766,6 +780,7 @@ private:
        }
 
        CheckBox* _upload;
+       CheckBox* _tms_passive;
        wxChoice* _tms_protocol;
        wxTextCtrl* _tms_ip;
        wxTextCtrl* _tms_path;