Browse Source

Free bytes for user can be displayed for IIS FTP server with FTP Directory Browsing > Directory Listing Options > Available bytes option enabled

Source commit: 98005a1c39d4d6ccd77a37e693f099dad39fc2ce
Martin Prikryl 9 years ago
parent
commit
2adb346576
2 changed files with 30 additions and 2 deletions
  1. 28 2
      source/core/FtpFileSystem.cpp
  2. 2 0
      source/core/FtpFileSystem.h

+ 28 - 2
source/core/FtpFileSystem.cpp

@@ -196,6 +196,7 @@ const UnicodeString CopySiteCommand(L"COPY");
 const UnicodeString HashCommand(L"HASH"); // Cerberos + FileZilla servers
 const UnicodeString HashCommand(L"HASH"); // Cerberos + FileZilla servers
 const UnicodeString AvblCommand(L"AVBL");
 const UnicodeString AvblCommand(L"AVBL");
 const UnicodeString XQuotaCommand(L"XQUOTA");
 const UnicodeString XQuotaCommand(L"XQUOTA");
+const UnicodeString DirectoryHasBytesPrefix(L"226-Directory has");
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 struct TSinkFileParams
 struct TSinkFileParams
 {
 {
@@ -271,6 +272,8 @@ __fastcall TFTPFileSystem::TFTPFileSystem(TTerminal * ATerminal):
   FSupportedSiteCommands.reset(CreateSortedStringList());
   FSupportedSiteCommands.reset(CreateSortedStringList());
   FCertificate = NULL;
   FCertificate = NULL;
   FPrivateKey = NULL;
   FPrivateKey = NULL;
+  FBytesAvailable = -1;
+  FBytesAvailableSuppoted = false;
 
 
   FChecksumAlgs.reset(new TStringList());
   FChecksumAlgs.reset(new TStringList());
   FChecksumCommands.reset(new TStringList());
   FChecksumCommands.reset(new TStringList());
@@ -2303,7 +2306,7 @@ bool __fastcall TFTPFileSystem::IsCapable(int Capability) const
       return FSupportsAnyChecksumFeature;
       return FSupportsAnyChecksumFeature;
 
 
     case fcCheckingSpaceAvailable:
     case fcCheckingSpaceAvailable:
-      return SupportsCommand(AvblCommand) || SupportsCommand(XQuotaCommand);
+      return FBytesAvailableSuppoted || SupportsCommand(AvblCommand) || SupportsCommand(XQuotaCommand);
 
 
     case fcModeChangingUpload:
     case fcModeChangingUpload:
     case fcLoadingAdditionalProperties:
     case fcLoadingAdditionalProperties:
@@ -2407,6 +2410,7 @@ void __fastcall TFTPFileSystem::ReadCurrentDirectory()
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 void __fastcall TFTPFileSystem::DoReadDirectory(TRemoteFileList * FileList)
 void __fastcall TFTPFileSystem::DoReadDirectory(TRemoteFileList * FileList)
 {
 {
+  FBytesAvailable = -1;
   FileList->Reset();
   FileList->Reset();
   // FZAPI does not list parent directory, add it
   // FZAPI does not list parent directory, add it
   FileList->AddFile(new TRemoteParentDirectory(FTerminal));
   FileList->AddFile(new TRemoteParentDirectory(FTerminal));
@@ -2808,7 +2812,14 @@ TStrings * __fastcall TFTPFileSystem::GetFixedPaths()
 void __fastcall TFTPFileSystem::SpaceAvailable(const UnicodeString Path,
 void __fastcall TFTPFileSystem::SpaceAvailable(const UnicodeString Path,
   TSpaceAvailable & ASpaceAvailable)
   TSpaceAvailable & ASpaceAvailable)
 {
 {
-  if (SupportsCommand(XQuotaCommand))
+  if (FBytesAvailableSuppoted)
+  {
+    std::unique_ptr<TRemoteFileList> DummyFileList(new TRemoteFileList());
+    DummyFileList->Directory = Path;
+    ReadDirectory(DummyFileList.get());
+    ASpaceAvailable.UnusedBytesAvailableToUser = FBytesAvailable;
+  }
+  else if (SupportsCommand(XQuotaCommand))
   {
   {
     // WS_FTP:
     // WS_FTP:
     // XQUOTA
     // XQUOTA
@@ -3618,6 +3629,21 @@ void __fastcall TFTPFileSystem::HandleReplyStatus(UnicodeString Response)
     }
     }
   }
   }
 
 
+
+  if (StartsStr(DirectoryHasBytesPrefix, Response))
+  {
+    UnicodeString Buf = Response;
+    Buf.Delete(1, DirectoryHasBytesPrefix.Length());
+    Buf = Buf.TrimLeft();
+    UnicodeString BytesStr = CutToChar(Buf, L' ', true);
+    BytesStr = ReplaceStr(BytesStr, L",", L"");
+    FBytesAvailable = StrToInt64Def(BytesStr, -1);
+    if (FBytesAvailable >= 0)
+    {
+      FBytesAvailableSuppoted = true;
+    }
+  }
+
   if (!FMultineResponse)
   if (!FMultineResponse)
   {
   {
     if (FLastCode == 220)
     if (FLastCode == 220)

+ 2 - 0
source/core/FtpFileSystem.h

@@ -276,6 +276,8 @@ private:
   EVP_PKEY * FPrivateKey;
   EVP_PKEY * FPrivateKey;
   bool FTransferActiveImmediately;
   bool FTransferActiveImmediately;
   bool FWindowsServer;
   bool FWindowsServer;
+  __int64 FBytesAvailable;
+  bool FBytesAvailableSuppoted;
   mutable UnicodeString FOptionScratch;
   mutable UnicodeString FOptionScratch;
 };
 };
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------