Browse Source

Bug fix: Error when uploading an empty folder in the foreground or any folder in the background to an FTP server with permissions configured

Source commit: e07f892ee17a913bc4a0edcbdad454f3b9c607ef
Martin Prikryl 4 years ago
parent
commit
e8ec884710
1 changed files with 8 additions and 3 deletions
  1. 8 3
      source/core/Terminal.cpp

+ 8 - 3
source/core/Terminal.cpp

@@ -7087,7 +7087,9 @@ bool __fastcall TTerminal::CreateTargetDirectory(
   if (DoCreate)
   {
     TRemoteProperties Properties;
-    if (CopyParam->PreserveRights)
+    // Do not even try with FTP, as while theoretically it supports setting permissions of created folders and it will try,
+    // it most likely fail as most FTP servers do not support SITE CHMOD.
+    if (CopyParam->PreserveRights && IsCapable[fcModeChangingUpload])
     {
       Properties.Valid = Properties.Valid << vpRights;
       Properties.Rights = CopyParam->RemoteFileRights(Attrs);
@@ -7106,7 +7108,7 @@ void __fastcall TTerminal::DirectorySource(
 {
   FFileSystem->TransferOnDirectory(TargetDir, CopyParam, Params);
 
-  UnicodeString DestFullName = UnixIncludeTrailingBackslash(TargetDir + DestDirectoryName);
+  UnicodeString DestFullName = TargetDir + DestDirectoryName;
 
   OperationProgress->SetFile(DirectoryName);
 
@@ -7134,7 +7136,10 @@ void __fastcall TTerminal::DirectorySource(
       {
         if (SearchRec.IsRealFile())
         {
-          SourceRobust(FileName, &SearchRec, DestFullName, CopyParam, Params, OperationProgress, (Flags & ~(tfFirstLevel | tfAutoResume)));
+          // Not sure if we need the trailing slash here, but we cannot use it in CreateTargetDirectory.
+          // At least FTP cannot handle it, when setting the new directory permissions.
+          UnicodeString ATargetDir = UnixIncludeTrailingBackslash(DestFullName);
+          SourceRobust(FileName, &SearchRec, ATargetDir, CopyParam, Params, OperationProgress, (Flags & ~(tfFirstLevel | tfAutoResume)));
           // FTP: if any file got uploaded (i.e. there were any file in the directory and at least one was not skipped),
           // do not try to create the directory, as it should be already created by FZAPI during upload
           PostCreateDir = false;