Browse Source

Bug 1768: Allow other 2xx responses to PWD command, not only the standard 257

https://winscp.net/tracker/1768
(cherry picked from commit 3a54bf3369244fe084d0b1bcede8c24fc4e57fb3)

Source commit: 47f75e56e5bd30b2c358bb6d305c0e9dfe211296
Martin Prikryl 4 years ago
parent
commit
445ac69841
3 changed files with 14 additions and 2 deletions
  1. 2 2
      source/core/FtpFileSystem.cpp
  2. 9 0
      source/core/SessionData.cpp
  3. 3 0
      source/core/SessionData.h

+ 2 - 2
source/core/FtpFileSystem.cpp

@@ -1960,8 +1960,8 @@ void __fastcall TFTPFileSystem::ReadCurrentDirectory()
       DebugAssert(Response != NULL);
       bool Result = false;
 
-      // the only allowed 2XX code to "PWD"
-      if ((Code == 257) &&
+      // The 257 is the only allowed 2XX code to "PWD"
+      if (((Code == 257) || FTerminal->SessionData->FtpAnyCodeForPwd) &&
           (Response->Count == 1))
       {
         UnicodeString Path = Response->Text;

+ 9 - 0
source/core/SessionData.cpp

@@ -276,6 +276,7 @@ void __fastcall TSessionData::DefaultSettings()
   FtpListAll = asAuto;
   FtpHost = asAuto;
   FtpWorkFromCwd = asAuto;
+  FtpAnyCodeForPwd = false;
   SslSessionReuse = true;
   TlsCertificateFile = L"";
 
@@ -447,6 +448,7 @@ void __fastcall TSessionData::NonPersistant()
   PROPERTY(FtpListAll); \
   PROPERTY(FtpHost); \
   PROPERTY(FtpWorkFromCwd); \
+  PROPERTY(FtpAnyCodeForPwd); \
   PROPERTY(SslSessionReuse); \
   PROPERTY(TlsCertificateFile); \
   \
@@ -864,6 +866,7 @@ void __fastcall TSessionData::DoLoad(THierarchicalStorage * Storage, bool PuttyI
   FtpListAll = Storage->ReadEnum(L"FtpListAll", FtpListAll, AutoSwitchMapping);
   FtpHost = Storage->ReadEnum(L"FtpHost", FtpHost, AutoSwitchMapping);
   FtpWorkFromCwd = Storage->ReadEnum(L"FtpWorkFromCwd", Storage->ReadEnum(L"FtpDeleteFromCwd", FtpWorkFromCwd), AutoSwitchMapping);
+  FtpAnyCodeForPwd = Storage->ReadBool(L"FtpAnyCodeForPwd", FtpAnyCodeForPwd);
   SslSessionReuse = Storage->ReadBool(L"SslSessionReuse", SslSessionReuse);
   TlsCertificateFile = Storage->ReadString(L"TlsCertificateFile", TlsCertificateFile);
 
@@ -1219,6 +1222,7 @@ void __fastcall TSessionData::DoSave(THierarchicalStorage * Storage,
     WRITE_DATA(Integer, FtpListAll);
     WRITE_DATA(Integer, FtpHost);
     WRITE_DATA(Integer, FtpWorkFromCwd);
+    WRITE_DATA(Bool, FtpAnyCodeForPwd);
     WRITE_DATA(Bool, SslSessionReuse);
     WRITE_DATA(String, TlsCertificateFile);
 
@@ -4130,6 +4134,11 @@ void __fastcall TSessionData::SetFtpWorkFromCwd(TAutoSwitch value)
   SET_SESSION_PROPERTY(FtpWorkFromCwd);
 }
 //---------------------------------------------------------------------
+void TSessionData::SetFtpAnyCodeForPwd(bool value)
+{
+  SET_SESSION_PROPERTY(FtpAnyCodeForPwd);
+}
+//---------------------------------------------------------------------
 void __fastcall TSessionData::SetSslSessionReuse(bool value)
 {
   SET_SESSION_PROPERTY(SslSessionReuse);

+ 3 - 0
source/core/SessionData.h

@@ -196,6 +196,7 @@ private:
   TAutoSwitch FFtpListAll;
   TAutoSwitch FFtpHost;
   TAutoSwitch FFtpWorkFromCwd;
+  bool FFtpAnyCodeForPwd;
   bool FSslSessionReuse;
   UnicodeString FTlsCertificateFile;
   TAddressFamily FAddressFamily;
@@ -371,6 +372,7 @@ private:
   void __fastcall SetFtpListAll(TAutoSwitch value);
   void __fastcall SetFtpHost(TAutoSwitch value);
   void __fastcall SetFtpWorkFromCwd(TAutoSwitch value);
+  void SetFtpAnyCodeForPwd(bool value);
   void __fastcall SetSslSessionReuse(bool value);
   void __fastcall SetTlsCertificateFile(UnicodeString value);
   UnicodeString __fastcall GetStorageKey();
@@ -642,6 +644,7 @@ public:
   __property TAutoSwitch FtpListAll = { read = FFtpListAll, write = SetFtpListAll };
   __property TAutoSwitch FtpHost = { read = FFtpHost, write = SetFtpHost };
   __property TAutoSwitch FtpWorkFromCwd = { read = FFtpWorkFromCwd, write = SetFtpWorkFromCwd };
+  __property bool FtpAnyCodeForPwd = { read = FFtpAnyCodeForPwd, write = SetFtpAnyCodeForPwd };
   __property bool SslSessionReuse = { read = FSslSessionReuse, write = SetSslSessionReuse };
   __property UnicodeString TlsCertificateFile = { read=FTlsCertificateFile, write=SetTlsCertificateFile };
   __property TDSTMode DSTMode = { read = FDSTMode, write = SetDSTMode };