فهرست منبع

Update 'getlog.cmd'

parv.ashwani 3 ماه پیش
والد
کامیت
4b924e2243
1فایلهای تغییر یافته به همراه389 افزوده شده و 238 حذف شده
  1. 389 238
      getlog.cmd

+ 389 - 238
getlog.cmd

@@ -1,295 +1,446 @@
 @echo off
-REM Usage: 
-REM   Normal mode: getlog <caseno> [filename]
-REM   Setup mode:  getlog setup
-REM   Folder setup: getlog foldersetup
-REM   Install:     getlog install
-
-set "SCRIPT_DIR=%~dp0"
-set "SCRIPT_PATH=%~f0"
-set "CONFIG_FILE=%SCRIPT_DIR%getlog_config.dat"
-set "FOLDER_CONFIG=%SCRIPT_DIR%getlog_folder.dat"
-
-REM Check for setup modes
-if /i "%~1"=="setup" (
-    call :setup
-    goto :eof
-)
-
-if /i "%~1"=="foldersetup" (
-    call :foldersetup
-    goto :eof
-)
+setlocal EnableExtensions EnableDelayedExpansion
 
-if /i "%~1"=="install" (
-    call :install
-    goto :eof
-)
+REM =====================================================
+REM getlog - NetScaler Case File Downloader
+REM Downloads case files from sjanalysis.citrite.net
+REM =====================================================
 
-if /i "%~1"=="uninstall" (
-    call :uninstall
-    goto :eof
+REM Check for pscp.exe (PuTTY SCP) or scp.exe
+set "SCP_TOOL="
+where pscp.exe >nul 2>&1
+if !ERRORLEVEL! EQU 0 (
+    set "SCP_TOOL=pscp.exe"
+    set "SCP_TYPE=PSCP"
+) else (
+    where scp.exe >nul 2>&1
+    if !ERRORLEVEL! EQU 0 (
+        set "SCP_TOOL=scp.exe"
+        set "SCP_TYPE=SCP"
+    )
 )
 
-REM Normal mode - check for required arguments
-if "%~1"=="" (
-    echo Usage: %~n0 ^<caseno^> [filename]
+if "%SCP_TOOL%"=="" (
+    echo ERROR: Neither pscp.exe nor scp.exe found in PATH.
     echo.
-    echo Examples:
-    echo   %~n0 1010011 support.tgz    - Download specific file
-    echo   %~n0 1010011                - Download entire case directory
+    echo Please install one of the following:
+    echo   - PuTTY ^(includes pscp.exe^) - https://www.putty.org/
+    echo   - OpenSSH Client ^(includes scp.exe^) - Built into Windows 10/11
     echo.
-    echo Setup mode: %~n0 setup
-    echo Folder setup: %~n0 foldersetup
-    echo Install: %~n0 install
+    pause
     exit /b 1
 )
 
-REM Load username from config or use default
-set "USERNAME=pashwani"
-if exist "%CONFIG_FILE%" (
-    set /p USERNAME=<"%CONFIG_FILE%"
-)
+REM =====================================================
+REM Configuration
+REM =====================================================
+set "REMOTE_SERVER=sjanalysis.citrite.net"
+set "REMOTE_BASE_PATH=/upload/ftp"
 
-REM Load folder preference or use default (SJLNT structure)
-set "FOLDER_MODE=SJLNT"
-if exist "%FOLDER_CONFIG%" (
-    set /p FOLDER_MODE=<"%FOLDER_CONFIG%"
+REM Prompt for case number if not provided
+if "%~1"=="" (
+    set /p CASENO=Enter Case Number: 
+) else (
+    set "CASENO=%~1"
 )
 
-set "CASE=%~1"
+if "%CASENO%"=="" (
+    echo ERROR: Case number cannot be empty.
+    exit /b 1
+)
 
-REM Check if filename is provided
+REM Prompt for credentials if not provided
 if "%~2"=="" (
-    set "DOWNLOAD_MODE=dir"
-    echo No filename provided. Will download entire case directory.
+    set /p USERNAME=Enter SSH Username: 
 ) else (
-    set "DOWNLOAD_MODE=file"
-    set "FILE=%~2"
+    set "USERNAME=%~2"
+)
+
+if "%USERNAME%"=="" (
+    echo ERROR: Username cannot be empty.
+    exit /b 1
 )
 
-REM Determine destination based on folder mode
-if /i "%FOLDER_MODE%"=="OLD" (
-    set "DEST=%USERPROFILE%\Downloads\Traces n Logs\%CASE%"
-    echo Using OLD folder structure: Traces n Logs
+if "%~3"=="" (
+    echo Enter SSH Password for %USERNAME%@%REMOTE_SERVER%:
+    set /p PASSWORD=
 ) else (
-    set "DEST=%USERPROFILE%\Downloads\SJLNT\%CASE%"
-    echo Using NEW folder structure: SJLNT
+    set "PASSWORD=%~3"
 )
 
-REM Create destination folder if it doesn't exist
+REM =====================================================
+REM Paths
+REM =====================================================
+set "REMOTE_CASE_PATH=%REMOTE_BASE_PATH%/%CASENO%"
+set "DEST=%USERPROFILE%\Downloads\SJLNT\%CASENO%"
+set "LOGFILE=%DEST%\download_%CASENO%.log"
+set "TEMP_LIST=%TEMP%\caselist_%CASENO%.txt"
+set "TEMP_FILTERED=%TEMP%\filtered_%CASENO%.txt"
+set "COLLECTOR_LIST=%TEMP%\collectors_%CASENO%.txt"
+set "ALL_FILES_LIST=%TEMP%\allfiles_%CASENO%.txt"
+
+echo.
+echo =====================================================
+echo  NetScaler Case Download Utility
+echo =====================================================
+echo Case Number    : %CASENO%
+echo Remote Server  : %REMOTE_SERVER%
+echo Remote Path    : %REMOTE_CASE_PATH%
+echo Local Dest     : %DEST%
+echo SCP Tool       : %SCP_TYPE%
+echo User           : %USERNAME%
+echo =====================================================
+echo.
+
+REM Create destination if missing
 if not exist "%DEST%" (
-    mkdir "%DEST%" 2>nul
-    if errorlevel 1 (
-        echo ERROR: Cannot create directory: %DEST%
-        echo Please check your permissions or disk space.
+    mkdir "%DEST%" 2>nul || (
+        echo ERROR: Failed to create destination folder: %DEST%
         exit /b 1
     )
-    echo Created folder: %DEST%
+    echo Created destination folder.
 )
 
-REM Perform download based on mode
-if "%DOWNLOAD_MODE%"=="dir" (
-    echo Downloading entire case directory using username: %USERNAME%
-    echo Remote source: %USERNAME%@sjanalysis.citrite.net:/upload/ftp/%CASE%
-    echo Local destination: %DEST%
-    echo.
-    echo This may take some time depending on the directory size...
-    echo.
-    
-    REM First, let's test the connection and check if the remote directory exists
-    echo Testing connection to remote server...
-    ssh -o BatchMode=yes -o ConnectTimeout=5 "%USERNAME%@sjanalysis.citrite.net" "ls -la /upload/ftp/%CASE%/ 2>/dev/null || echo 'Directory not found'" >nul 2>&1
-    
-    echo Starting download...
-    
-    REM Use scp -r for recursive directory copy - REMOVE trailing slash from source
-    REM The issue was likely with the trailing slash in the source path
-    scp -rp "%USERNAME%@sjanalysis.citrite.net:/upload/ftp/%CASE%" "%DEST%"
-    
-    if errorlevel 1 (
-        echo.
-        echo SCP failed with error code: %errorlevel%
-        echo Possible issues:
-        echo   1. Case directory %CASE% doesn't exist on remote server
-        echo   2. Network connectivity issue
-        echo   3. Incorrect username
-        echo.
-        echo You can run 'getlog setup' to reconfigure username.
-        echo To check if directory exists: ssh %USERNAME%@sjanalysis.citrite.net "ls -la /upload/ftp/%CASE%/"
-        exit /b 1
-    )
-    
-    echo.
-    echo Entire case directory downloaded successfully to: %DEST%
-    echo.
-    
-    REM Show downloaded contents
-    echo Directory contents:
-    echo -------------------
-    dir /b "%DEST%" 2>nul || echo (No files downloaded or directory empty)
+REM Create subdirectories for organization
+if not exist "%DEST%\configs" mkdir "%DEST%\configs"
+if not exist "%DEST%\captures" mkdir "%DEST%\captures"
+if not exist "%DEST%\media" mkdir "%DEST%\media"
+
+REM Initialize log file
+echo Download Log - Case: %CASENO% > "%LOGFILE%"
+echo Date/Time: %DATE% %TIME% >> "%LOGFILE%"
+echo Remote Server: %REMOTE_SERVER% >> "%LOGFILE%"
+echo User: %USERNAME% >> "%LOGFILE%"
+echo ================================================== >> "%LOGFILE%"
+echo. >> "%LOGFILE%"
+
+REM =====================================================
+REM Test SSH connection and verify case directory
+REM =====================================================
+echo [1/5] Testing SSH connection...
+echo Testing SSH connection... >> "%LOGFILE%"
+
+if "%SCP_TYPE%"=="PSCP" (
+    echo y | plink.exe -batch -pw "%PASSWORD%" %USERNAME%@%REMOTE_SERVER% "test -d %REMOTE_CASE_PATH% && echo OK || echo NOTFOUND" 2>nul | findstr /V /C:"Keyboard" /C:"prompts from server" > "%TEMP_LIST%"
 ) else (
-    echo Downloading file using username: %USERNAME%
-    echo Remote file: /upload/ftp/%CASE%/%FILE%
-    
-    scp -p "%USERNAME%@sjanalysis.citrite.net:/upload/ftp/%CASE%/%FILE%" "%DEST%"
-    
-    if errorlevel 1 (
-        echo SCP failed with error code: %errorlevel%
-        echo Please check:
-        echo   1. File exists on remote server
-        echo   2. Username is correct
-        echo   3. Network connection
-        echo.
-        echo Run 'getlog setup' to reconfigure username.
-        exit /b 1
-    )
-    
-    echo.
-    echo File downloaded successfully to: %DEST%
-    echo Full path: %DEST%\%FILE%
+    sshpass -p "%PASSWORD%" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL %USERNAME%@%REMOTE_SERVER% "test -d %REMOTE_CASE_PATH% && echo OK || echo NOTFOUND" > "%TEMP_LIST%" 2>&1
 )
 
-goto :eof
+if !ERRORLEVEL! NEQ 0 (
+    echo ERROR: SSH connection failed. >> "%LOGFILE%"
+    type "%TEMP_LIST%" >> "%LOGFILE%"
+    echo ERROR: SSH connection failed.
+    echo Check credentials and network connectivity.
+    echo See log: %LOGFILE%
+    del "%TEMP_LIST%" 2>nul
+    pause
+    exit /b 1
+)
 
-:setup
-echo Current username: %USERNAME%
-echo.
-set /p "NEW_USER=Enter new username: "
-if "%NEW_USER%"=="" (
-    echo Username cannot be empty.
-    goto :setup
+findstr /C:"OK" "%TEMP_LIST%" >nul
+if !ERRORLEVEL! NEQ 0 (
+    echo ERROR: Case directory not found on server: %REMOTE_CASE_PATH% >> "%LOGFILE%"
+    echo ERROR: Case directory not found on server.
+    echo Path: %REMOTE_CASE_PATH%
+    echo Please verify the case number.
+    del "%TEMP_LIST%" 2>nul
+    pause
+    exit /b 1
 )
-echo %NEW_USER%>"%CONFIG_FILE%"
-echo Username saved successfully.
-goto :eof
 
-:foldersetup
-echo.
-echo Current folder structure: %FOLDER_MODE%
-echo.
-echo Available options:
-echo   1. SJLNT (new) - %USERPROFILE%\Downloads\SJLNT\<caseno>
-echo   2. OLD (legacy) - %USERPROFILE%\Downloads\Traces n Logs\<caseno>
+echo   Connection successful.
+echo Connection successful. >> "%LOGFILE%"
+
+REM =====================================================
+REM Single SSH call to get all required info
+REM Collectors + All files in case root
+REM =====================================================
 echo.
-set /p "FOLDER_CHOICE=Enter folder structure (1 for SJLNT, 2 for OLD): "
-
-if "%FOLDER_CHOICE%"=="1" (
-    echo SJLNT>"%FOLDER_CONFIG%"
-    echo Folder structure set to SJLNT (new).
-) else if "%FOLDER_CHOICE%"=="2" (
-    echo OLD>"%FOLDER_CONFIG%"
-    echo Folder structure set to OLD (legacy).
+echo [2/5] Scanning case directory...
+echo Scanning case directory... >> "%LOGFILE%"
+
+if "%SCP_TYPE%"=="PSCP" (
+    plink.exe -batch -pw "%PASSWORD%" %USERNAME%@%REMOTE_SERVER% "echo '===COLLECTORS==='; find %REMOTE_CASE_PATH% -maxdepth 1 -type d -name 'collector_*' 2>/dev/null; echo '===FILES==='; find %REMOTE_CASE_PATH% -maxdepth 1 -type f \( -name '*.cap' -o -name '*.pcap' -o -name '*.pcapng' -o -name '*.sslkeys' -o -name '*.keys' -o -name '*.har' -o -name '*.xml' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' -o -name '*.gif' -o -name '*.bmp' -o -name '*.webp' -o -name '*.tiff' -o -name '*.svg' -o -name '*.txt' -o -name '*.log' -o -name '*.csv' -o -name '*.json' \) 2>/dev/null" 2>nul | findstr /V /C:"Keyboard" /C:"prompts from server" > "%ALL_FILES_LIST%"
 ) else (
-    echo Invalid choice. Using default (SJLNT).
-    echo SJLNT>"%FOLDER_CONFIG%"
+    sshpass -p "%PASSWORD%" ssh -o StrictHostKeyChecking=no %USERNAME%@%REMOTE_SERVER% "echo '===COLLECTORS==='; find %REMOTE_CASE_PATH% -maxdepth 1 -type d -name 'collector_*' 2>/dev/null; echo '===FILES==='; find %REMOTE_CASE_PATH% -maxdepth 1 -type f \( -name '*.cap' -o -name '*.pcap' -o -name '*.pcapng' -o -name '*.sslkeys' -o -name '*.keys' -o -name '*.har' -o -name '*.xml' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' -o -name '*.gif' -o -name '*.bmp' -o -name '*.webp' -o -name '*.tiff' -o -name '*.svg' -o -name '*.txt' -o -name '*.log' -o -name '*.csv' -o -name '*.json' \) 2>/dev/null" > "%ALL_FILES_LIST%"
 )
-echo.
-echo Run: getlog ^<caseno^> [filename] to download files.
-goto :eof
 
-:install
-echo Installing getlog for global access...
-echo ========================================
-echo.
+REM Parse collectors from combined output
+set "IN_COLLECTORS=0"
+set "IN_FILES=0"
+echo. > "%COLLECTOR_LIST%"
+echo. > "%TEMP_LIST%"
 
-REM Check if already in PATH
-echo %PATH% | find /i "%SCRIPT_DIR%" >nul
-if not errorlevel 1 (
-    echo Script is already in PATH.
-    echo Location: %SCRIPT_DIR%
-    goto :check_admin
+for /f "usebackq delims=" %%A in ("%ALL_FILES_LIST%") do (
+    set "LINE=%%A"
+    
+    REM Check for section markers
+    echo !LINE! | findstr /C:"===COLLECTORS===" >nul
+    if !ERRORLEVEL! EQU 0 (
+        set "IN_COLLECTORS=1"
+        set "IN_FILES=0"
+    ) else (
+        echo !LINE! | findstr /C:"===FILES===" >nul
+        if !ERRORLEVEL! EQU 0 (
+            set "IN_COLLECTORS=0"
+            set "IN_FILES=1"
+        ) else (
+            REM Skip empty lines and filter noise
+            if not "!LINE!"=="" (
+                echo !LINE! | findstr /C:"Keyboard" /C:"prompts" /C:"authentication" >nul
+                if !ERRORLEVEL! NEQ 0 (
+                    if !IN_COLLECTORS! EQU 1 (
+                        echo !LINE!>> "%COLLECTOR_LIST%"
+                    )
+                    if !IN_FILES! EQU 1 (
+                        echo !LINE!>> "%TEMP_LIST%"
+                    )
+                )
+            )
+        )
+    )
 )
 
-REM Check for administrator privileges
-net session >nul 2>&1
-if %errorlevel% neq 0 (
-    echo Warning: Administrative privileges required for system-wide installation.
-    echo You can still install for current user only.
-    echo.
-    choice /c SU /m "Install for: [S]ystem (admin required) or [U]ser"
-    if errorlevel 2 goto :user_install
-    goto :system_install
+REM Count collectors
+set "COLLECTOR_COUNT=0"
+for /f "usebackq delims=" %%A in ("%COLLECTOR_LIST%") do (
+    set "LINE=%%A"
+    if not "!LINE!"=="" (
+        echo !LINE! | findstr /C:"collector_" >nul
+        if !ERRORLEVEL! EQU 0 (
+            set /a COLLECTOR_COUNT+=1
+            for %%B in ("!LINE!") do echo   Found: %%~nxB
+            echo Found collector: !LINE! >> "%LOGFILE%"
+        )
+    )
 )
 
-:system_install
-echo Installing for all users (requires admin)...
-echo.
-REM Add to system PATH using setx
-setx PATH "%PATH%;%SCRIPT_DIR%" /M >nul
-if errorlevel 1 (
-    echo Failed to update system PATH. Trying user PATH...
-    goto :user_install
+if %COLLECTOR_COUNT% EQU 0 (
+    echo   No collector bundles found.
+    echo No collector bundles found. >> "%LOGFILE%"
 ) else (
-    echo Successfully added to system PATH.
-    echo Script directory: %SCRIPT_DIR%
-    echo.
-    echo You may need to restart your terminal for changes to take effect.
+    echo   Total collectors found: %COLLECTOR_COUNT%
 )
-goto :eof
 
-:user_install
-echo Installing for current user only...
+REM =====================================================
+REM Download Saved Config (ns.conf from nsconfig folder)
+REM Inside collector bundles only
+REM =====================================================
 echo.
-REM Add to user PATH
-setx PATH "%PATH%;%SCRIPT_DIR%" >nul
-if errorlevel 1 (
-    echo Failed to update user PATH.
-    echo.
-    echo Manual installation steps:
-    echo 1. Copy this script to a directory already in your PATH
-    echo 2. Or add this directory to your PATH manually:
-    echo    %SCRIPT_DIR%
-) else (
-    echo Successfully added to user PATH.
-    echo Script directory: %SCRIPT_DIR%
-    echo.
-    echo You may need to restart your terminal for changes to take effect.
+echo [3/5] Downloading saved configurations ^(ns.conf^)...
+echo Downloading saved configurations... >> "%LOGFILE%"
+
+set "CONFIG_COUNT=0"
+for /f "usebackq delims=" %%C in ("%COLLECTOR_LIST%") do (
+    set "COLLECTOR_PATH=%%C"
+    
+    REM Skip empty lines and filter noise
+    if not "!COLLECTOR_PATH!"=="" (
+        echo !COLLECTOR_PATH! | findstr /C:"collector_" >nul
+        if !ERRORLEVEL! EQU 0 (
+            for %%D in ("!COLLECTOR_PATH!") do set "COLLECTOR_NAME=%%~nxD"
+            
+            echo   Checking !COLLECTOR_NAME! for ns.conf...
+            
+            set "DEST_FILENAME=ns.conf_!COLLECTOR_NAME!"
+            
+            if "%SCP_TYPE%"=="PSCP" (
+                pscp.exe -batch -pw "%PASSWORD%" -q "%USERNAME%@%REMOTE_SERVER%:!COLLECTOR_PATH!/nsconfig/ns.conf" "%DEST%\configs\!DEST_FILENAME!" >nul 2>&1
+            ) else (
+                scp -o StrictHostKeyChecking=no -q "%USERNAME%@%REMOTE_SERVER%:!COLLECTOR_PATH!/nsconfig/ns.conf" "%DEST%\configs\!DEST_FILENAME!" 2>nul
+            )
+            
+            if exist "%DEST%\configs\!DEST_FILENAME!" (
+                echo     Downloaded: !DEST_FILENAME!
+                echo Downloaded: !DEST_FILENAME! >> "%LOGFILE%"
+                set /a CONFIG_COUNT+=1
+            ) else (
+                echo     ns.conf not found in !COLLECTOR_NAME!
+            )
+        )
+    )
 )
-goto :eof
 
-:check_admin
-echo.
-echo You can now run 'getlog' from any directory.
-echo.
-goto :eof
+echo   Saved configs downloaded: %CONFIG_COUNT%
 
-:uninstall
-echo Uninstalling getlog...
-echo ======================
+REM =====================================================
+REM Download Running Config (ns_running_config.conf)
+REM Inside collector bundles only
+REM =====================================================
 echo.
-echo Warning: This will only remove the script directory from PATH.
-echo The script files and configuration will not be deleted.
+echo [4/5] Downloading running configurations...
+echo Downloading running configurations... >> "%LOGFILE%"
+
+set "RUNNING_COUNT=0"
+for /f "usebackq delims=" %%C in ("%COLLECTOR_LIST%") do (
+    set "COLLECTOR_PATH=%%C"
+    
+    REM Skip empty lines and filter noise
+    if not "!COLLECTOR_PATH!"=="" (
+        echo !COLLECTOR_PATH! | findstr /C:"collector_" >nul
+        if !ERRORLEVEL! EQU 0 (
+            for %%D in ("!COLLECTOR_PATH!") do set "COLLECTOR_NAME=%%~nxD"
+            
+            echo   Checking !COLLECTOR_NAME! for running config...
+            
+            set "DEST_FILENAME=ns_running_config.conf_!COLLECTOR_NAME!"
+            
+            if "%SCP_TYPE%"=="PSCP" (
+                pscp.exe -batch -pw "%PASSWORD%" -q "%USERNAME%@%REMOTE_SERVER%:!COLLECTOR_PATH!/shell/ns_running_config.conf" "%DEST%\configs\!DEST_FILENAME!" >nul 2>&1
+            ) else (
+                scp -o StrictHostKeyChecking=no -q "%USERNAME%@%REMOTE_SERVER%:!COLLECTOR_PATH!/shell/ns_running_config.conf" "%DEST%\configs\!DEST_FILENAME!" 2>nul
+            )
+            
+            if exist "%DEST%\configs\!DEST_FILENAME!" (
+                echo     Downloaded: !DEST_FILENAME!
+                echo Downloaded: !DEST_FILENAME! >> "%LOGFILE%"
+                set /a RUNNING_COUNT+=1
+            ) else (
+                echo     Running config not found in !COLLECTOR_NAME!
+            )
+        )
+    )
+)
+
+echo   Running configs downloaded: %RUNNING_COUNT%
+
+REM =====================================================
+REM Download Capture and Media Files
+REM OUTSIDE collector bundles only (case root level)
+REM Using pre-fetched file list
+REM =====================================================
 echo.
-echo Script location: %SCRIPT_DIR%
+echo [5/5] Downloading files from case directory...
+echo Downloading files from case root... >> "%LOGFILE%"
+
+set "CAPTURE_COUNT=0"
+set "MEDIA_COUNT=0"
+set "OTHER_COUNT=0"
+
+for /f "usebackq delims=" %%F in ("%TEMP_LIST%") do (
+    set "REMOTE_FILE=%%F"
+    
+    REM Skip empty lines and filter noise
+    if not "!REMOTE_FILE!"=="" (
+        echo !REMOTE_FILE! | findstr /C:"Keyboard" /C:"prompts" /C:"authentication" >nul
+        if !ERRORLEVEL! NEQ 0 (
+            for %%G in ("!REMOTE_FILE!") do (
+                set "FILENAME=%%~nxG"
+                set "FILEEXT=%%~xG"
+            )
+            
+            if not "!FILENAME!"=="" (
+                REM Determine file type and destination
+                set "FILE_DEST="
+                set "FILE_TYPE="
+                
+                REM Check if capture file
+                echo !FILEEXT! | findstr /I /C:".cap" /C:".pcap" /C:".pcapng" /C:".sslkeys" /C:".keys" /C:".har" >nul
+                if !ERRORLEVEL! EQU 0 (
+                    set "FILE_DEST=%DEST%\captures\!FILENAME!"
+                    set "FILE_TYPE=capture"
+                )
+                
+                REM Check if image file
+                echo !FILEEXT! | findstr /I /C:".jpg" /C:".jpeg" /C:".png" /C:".gif" /C:".bmp" /C:".webp" /C:".tiff" /C:".svg" >nul
+                if !ERRORLEVEL! EQU 0 (
+                    set "FILE_DEST=%DEST%\media\!FILENAME!"
+                    set "FILE_TYPE=media"
+                )
+                
+                REM Check if other file (txt, log, xml, json, csv)
+                echo !FILEEXT! | findstr /I /C:".txt" /C:".log" /C:".xml" /C:".json" /C:".csv" >nul
+                if !ERRORLEVEL! EQU 0 (
+                    set "FILE_DEST=%DEST%\!FILENAME!"
+                    set "FILE_TYPE=other"
+                )
+                
+                REM Download the file
+                if defined FILE_DEST (
+                    echo   Downloading: !FILENAME!
+                    
+                    if "%SCP_TYPE%"=="PSCP" (
+                        pscp.exe -batch -pw "%PASSWORD%" -q "%USERNAME%@%REMOTE_SERVER%:!REMOTE_FILE!" "!FILE_DEST!" >nul 2>&1
+                    ) else (
+                        scp -o StrictHostKeyChecking=no -q "%USERNAME%@%REMOTE_SERVER%:!REMOTE_FILE!" "!FILE_DEST!" 2>nul
+                    )
+                    
+                    if exist "!FILE_DEST!" (
+                        echo     Downloaded: !FILENAME!
+                        echo Downloaded !FILE_TYPE!: !FILENAME! >> "%LOGFILE%"
+                        
+                        if "!FILE_TYPE!"=="capture" set /a CAPTURE_COUNT+=1
+                        if "!FILE_TYPE!"=="media" set /a MEDIA_COUNT+=1
+                        if "!FILE_TYPE!"=="other" set /a OTHER_COUNT+=1
+                    )
+                )
+            )
+        )
+    )
+)
+
 echo.
+echo   Capture files downloaded: %CAPTURE_COUNT%
+echo   Media files downloaded: %MEDIA_COUNT%
+echo   Other files downloaded: %OTHER_COUNT%
+
+REM =====================================================
+REM Cleanup and Summary
+REM =====================================================
+del "%TEMP_LIST%" 2>nul
+del "%TEMP_FILTERED%" 2>nul
+del "%COLLECTOR_LIST%" 2>nul
+del "%ALL_FILES_LIST%" 2>nul
 
-choice /c YN /m "Are you sure you want to remove getlog from PATH? [Y/N]"
-if errorlevel 2 (
-    echo Uninstall cancelled.
-    goto :eof
+REM Remove empty directories
+for %%D in (configs captures media) do (
+    dir /b "%DEST%\%%D" 2>nul | findstr "." >nul || rmdir "%DEST%\%%D" 2>nul
 )
 
 echo.
-echo Removing from PATH...
-
-REM Create a temporary PowerShell script to safely remove from PATH
-set "PS_SCRIPT=%TEMP%\remove_from_path.ps1"
-(
-echo $currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
-echo $systemPath = [Environment]::GetEnvironmentVariable('PATH', 'Machine')
-echo $scriptDir = "%SCRIPT_DIR:\=/%"
-echo $newUserPath = ($currentPath -split ';' ^| Where-Object { $_ -ne "%SCRIPT_DIR%" } ^| Where-Object { $_ -ne "" }) -join ';'
-echo $newSystemPath = ($systemPath -split ';' ^| Where-Object { $_ -ne "%SCRIPT_DIR%" } ^| Where-Object { $_ -ne "" }) -join ';'
-echo [Environment]::SetEnvironmentVariable('PATH', $newUserPath, 'User')
-echo [Environment]::SetEnvironmentVariable('PATH', $newSystemPath, 'Machine')
-echo "PATH updated. You may need to restart your terminal."
-) > "%PS_SCRIPT%"
-
-powershell -ExecutionPolicy Bypass -File "%PS_SCRIPT%"
-del "%PS_SCRIPT%" >nul 2>&1
+echo =====================================================
+echo  Download Complete - Summary
+echo =====================================================
+echo.
+echo  FROM COLLECTOR BUNDLES:
+echo    Collector bundles found  : %COLLECTOR_COUNT%
+echo    Saved configs ^(ns.conf^)  : %CONFIG_COUNT%
+echo    Running configs          : %RUNNING_COUNT%
+echo.
+echo  FROM CASE ROOT DIRECTORY:
+echo    Capture files ^(pcap,har^) : %CAPTURE_COUNT%
+echo    Media files ^(images^)     : %MEDIA_COUNT%
+echo    Other files ^(xml,txt^)    : %OTHER_COUNT%
+echo.
+echo Destination folder:
+echo %DEST%
+echo.
+echo Log file:
+echo %LOGFILE%
+echo.
+
+REM Write summary to log
+echo. >> "%LOGFILE%"
+echo ================================================== >> "%LOGFILE%"
+echo SUMMARY >> "%LOGFILE%"
+echo ================================================== >> "%LOGFILE%"
+echo FROM COLLECTOR BUNDLES: >> "%LOGFILE%"
+echo   Collector bundles found  : %COLLECTOR_COUNT% >> "%LOGFILE%"
+echo   Saved configs            : %CONFIG_COUNT% >> "%LOGFILE%"
+echo   Running configs          : %RUNNING_COUNT% >> "%LOGFILE%"
+echo. >> "%LOGFILE%"
+echo FROM CASE ROOT DIRECTORY: >> "%LOGFILE%"
+echo   Capture files            : %CAPTURE_COUNT% >> "%LOGFILE%"
+echo   Media files              : %MEDIA_COUNT% >> "%LOGFILE%"
+echo   Other files              : %OTHER_COUNT% >> "%LOGFILE%"
+echo ================================================== >> "%LOGFILE%"
 
+echo =====================================================
 echo.
-echo getlog has been removed from PATH.
-echo Note: Script files and configuration remain in: %SCRIPT_DIR%
-goto :eof
+
+REM Open destination folder
+choice /C YN /M "Open destination folder now?"
+if !ERRORLEVEL! EQU 1 explorer "%DEST%"
+
+endlocal
+exit /b 0