Przeglądaj źródła

Use MVS compatibility mode only when initial path is not *nix-like

Part of Bug 2069
https://winscp.net/tracker/2069

(cherry picked from commit 6aab3517d5b6ee3dfb4a990f335f7d777d2cb330)

Source commit: fb64e5b0a916fbc1628304c338607a056851e759
Martin Prikryl 3 lat temu
rodzic
commit
a267e61a4b
2 zmienionych plików z 34 dodań i 16 usunięć
  1. 33 16
      source/core/FtpFileSystem.cpp
  2. 1 0
      source/core/FtpFileSystem.h

+ 33 - 16
source/core/FtpFileSystem.cpp

@@ -1905,7 +1905,29 @@ void __fastcall TFTPFileSystem::DoStartup()
   }
 
   // retrieve initialize working directory to save it as home directory
-  ReadCurrentDirectory();
+  UnicodeString RawPwd = DoReadCurrentDirectory();
+
+  // Full name is "MVS is the operating system of this server. FTP Server is running on ..."
+  // (the ... can be "z/OS")
+  // https://www.ibm.com/docs/en/zos/latest?topic=2rc-215-mvs-is-operating-system-this-server-ftp-server-is-running-name
+  // FZPI has a different incompatible detection.
+  // MVS FTP servers have two separate MVS and Unix file systems cooexisting in the same session.
+  // Use the "MVS mode" only if we are starting in the MVS file system.
+  // WinSCP cannot handle switching between these two file system in one session.
+  FMVS = (FSystem.SubString(1, 3) == L"MVS") && !UnixIsAbsolutePath(RawPwd);
+  if (FMVS)
+  {
+    FTerminal->LogEvent(L"MVS system detected.");
+  }
+
+  // Other systems are detected in HandleReplyStatus
+
+  if ((FWorkFromCwd == asAuto) && (FVMS || FMVS))
+  {
+    FTerminal->LogEvent(L"Server is known to require use of relative paths");
+    FWorkFromCwd = asOn;
+  }
+
   FHomeDirectory = FCurrentDirectory;
 }
 //---------------------------------------------------------------------------
@@ -1988,6 +2010,12 @@ void __fastcall TFTPFileSystem::LookupUsersGroups()
 //---------------------------------------------------------------------------
 void __fastcall TFTPFileSystem::ReadCurrentDirectory()
 {
+  DoReadCurrentDirectory();
+}
+//---------------------------------------------------------------------------
+UnicodeString TFTPFileSystem::DoReadCurrentDirectory()
+{
+  UnicodeString Path;
   // ask the server for current directory on startup only
   // and immediately after call to CWD,
   // later our current directory may be not synchronized with FZAPI current
@@ -2010,7 +2038,7 @@ void __fastcall TFTPFileSystem::ReadCurrentDirectory()
       if (((Code == 257) || FTerminal->SessionData->FtpAnyCodeForPwd) &&
           (Response->Count == 1))
       {
-        UnicodeString Path = Response->Text;
+        Path = Response->Text;
 
         int P = Path.Pos(L"\"");
         if (P == 0)
@@ -2055,6 +2083,7 @@ void __fastcall TFTPFileSystem::ReadCurrentDirectory()
       delete Response;
     }
   }
+  return Path;
 }
 //---------------------------------------------------------------------------
 void __fastcall TFTPFileSystem::DoReadDirectory(TRemoteFileList * FileList)
@@ -3526,15 +3555,6 @@ void __fastcall TFTPFileSystem::HandleReplyStatus(UnicodeString Response)
         FSystem = FLastResponse->Text.TrimRight();
         // FZAPI has own detection of MVS/VMS
 
-        // full name is "MVS is the operating system of this server. FTP Server is running on ..."
-        // (the ... can be "z/OS")
-        // https://www.ibm.com/docs/en/zos/latest?topic=2rc-215-mvs-is-operating-system-this-server-ftp-server-is-running-name
-        // FZPI has a different incompatible detection.
-        FMVS = (FSystem.SubString(1, 3) == L"MVS");
-        if (FMVS)
-        {
-          FTerminal->LogEvent(L"MVS system detected.");
-        }
         // The FWelcomeMessage usually contains "Microsoft FTP Service" but can be empty
         if (ContainsText(FSystem, L"Windows_NT"))
         {
@@ -3556,11 +3576,6 @@ void __fastcall TFTPFileSystem::HandleReplyStatus(UnicodeString Response)
           FTerminal->LogEvent(L"Server is known not to support LIST -a");
           FListAll = asOff;
         }
-        if ((FWorkFromCwd == asAuto) && (FVMS || FMVS))
-        {
-          FTerminal->LogEvent(L"Server is known to require use of relative paths");
-          FWorkFromCwd = asOn;
-        }
         // 220-FileZilla Server 1.0.1
         // 220 Please visit https://filezilla-project.org/
         // SYST
@@ -3571,6 +3586,8 @@ void __fastcall TFTPFileSystem::HandleReplyStatus(UnicodeString Response)
           FTerminal->LogEvent(L"FileZilla server detected.");
           FFileZilla = true;
         }
+
+        // MVS is detected in DoStartup
       }
       else
       {

+ 1 - 0
source/core/FtpFileSystem.h

@@ -217,6 +217,7 @@ protected:
   bool __fastcall CanTransferSkipList(int Params, unsigned int Flags, const TCopyParamType * CopyParam);
   void __fastcall Disconnect();
   UnicodeString RemoteExtractFilePath(const UnicodeString & Path);
+  UnicodeString DoReadCurrentDirectory();
 
   static bool __fastcall Unquote(UnicodeString & Str);