#-------------------------------------------------------- # File: dirGet2.eps # # Script will alert the user to all files in excess of ALERTSIZE and allow # them to specify which ones they want to include in the download #-------------------------------------------------------- # Ensure the user doesn't crash/slow EP (stores log dir in memory) int $MAXFILES = 1000; string $commandLineOption; string $beforeDATE; string $afterDATE; string $directory; string $timeType; string $fileMask; int $alertSize = 2000000; int $pauseCount; int $ageHours; int $throttleBytes; int $counter = 0; int $totalSize = 0; int $numberOfFiles = 0; bool $recursiveFlag = false; bool $individualFlag = false; bool $foregroundFlag = false; bool $maxFileLimit = false; string $temp; @echo off; @case-sensitive off; #-------------------------------------------------------- # Parse the command line options #-------------------------------------------------------- if ($argc == 1) { $argv[1] = "-help"; } while (defined($argv[$counter])) { $temp = split("-", $argv[$counter]); $counter += 1; if (defined($temp[1])) { $commandLineOption = $temp[1]; if (($commandLineOption == "h") || ($commandLineOption == "help") || ($commandLineOption == "?")) { echo "\nUsage: script dirGet2.eps _Options_"; echo " Get all/some files from a directory. The script attempts to use the get"; echo " command with a mask, but downloads the files individually if the user"; echo " chooses to exclude some files."; echo "\nOptions:"; echo " [-path ] - REQUIRED"; echo " Gets the files from specified directory"; echo " [-mask ] - REQUIRED"; echo " Gets only the files with the specified mask. Default = *.*"; echo " [-alert ]"; echo " Alert the user to any file larger than filesize. Default = 2000000"; echo " [-after ]"; echo " Only get files with timestamps after the given date"; echo " [-before ]"; echo " Only get files with timestamps before the given date"; echo " [-age ]"; echo " Retrieves files that are at most 'hours' old"; echo " [-time ]"; echo " Time type to use in after/before/age. Default = modified"; echo " [-pause <#>]"; echo " Pause after every # downloads (doesn't work if getting all files)"; echo " [-throttle <# bytes>]"; echo " Reduces the network traffic for the download to # bytes per second"; echo " [-individual] or [-i]"; echo " Force individual file download, even if you want to get ALL files"; echo " [-recursive] or [-r]"; echo " Get files in subdirectories also"; echo " [-foreground] or [-f]"; echo " Get files one at a time (don't put them in the background)"; return true; } else if (($commandLineOption == "r") || ($commandLineOption == "recursive")) { $recursiveFlag = true; } else if (($commandLineOption == "i") || ($commandLineOption == "individual")) { $individualFlag = true; } else if (($commandLineOption == "f") || ($commandLineOption == "foreground")) { $foregroundFlag = true; } else { if (defined($argv[$counter])) { if ($commandLineOption == "path") { $directory = $argv[$counter]; } else if ($commandLineOption == "mask") { $fileMask = $argv[$counter]; } else if ($commandLineOption == "after") { $afterDATE = $argv[$counter]; } else if ($commandLineOption == "before") { $beforeDATE = $argv[$counter]; } else if ($commandLineOption == "age") { $ageHours = $argv[$counter]; } else if ($commandLineOption == "time") { $timeType = $argv[$counter]; } else if ($commandLineOption == "alert") { $alertSize = $argv[$counter]; } else if ($commandLineOption == "pause") { $pauseCount = $argv[$counter]; } else if ($commandLineOption == "throttle") { $throttleBytes = $argv[$counter]; } else if ($commandLineOption == "max") { # Do nothing with Max } else { echo "OPTION $temp[1] not recognized (-h for help)"; return false; } $counter++; } else { echo "OPTION $temp[1] requires data (-h for help)"; return false; } } } } ifnot (defined($directory) && defined($fileMask)) { echo "-PATH and -MASK are a required input fields (-h for help)"; return true; } #-------------------------------------------------------- # Create the flags for the dir and get statements that will be executed #-------------------------------------------------------- string $dirAndGetFlags = ""; if (defined($afterDate)) { $dirAndGetFlags = "$dirAndGetFlags -after $afterDate"; } if (defined($beforeDate)) { $dirAndGetFlags = "$dirAndGetFlags -before $beforeDate"; } if (defined($ageHours)) { $dirAndGetFlags = "$dirAndGetFlags -age $ageHours"; } if (defined($timeType)) { $dirAndGetFlags = "$dirAndGetFlags -time $timeType"; } if ($recursiveFlag) { $dirAndGetFlags = "$dirAndGetFlags -recursive"; } #-------------------------------------------------------- # Display all files that are > the alert size #-------------------------------------------------------- @record on; `log dir $fileMask -path "$directory" $dirAndGetFlags -max $MAXFILES`; @record off; bool $selectiveDownload; string $tempPath = GetCmdData("path"); string $tempName = GetCmdData("name"); int $tempSize = GetCmdData("size"); int $counter2 = 0; string $option = "a"; int $arrayHolder; $counter = 0; while ($counter < sizeof($tempName)) { $totalSize += $tempSize[$counter]; if ($tempSize[$counter] > 0) { $numberOfFiles++; } if ($tempSize[$counter] >= $alertSize) { $arrayHolder[$counter2] = $counter; $counter2++; if ($counter2 == 1) { echo "\nLARGE FILES..."; echo "q. Quit"; echo "a. Include all the files in the download"; echo "0. Exclude all the files from the download"; } echo "$counter2. $tempSize[$counter] - $tempPath[$counter]\\$tempName[$counter]"; } $counter++; } # Ensure the user doesn't crash EP (or slow it down to a crawl) if ($counter >= $MAXFILES) { ifnot (prompt "\n\nWARNING...you've reached the max file limit (could be a coincidence). Recommend narrowing the focus of your dirget. Continue?") { undef($arrayHolder); undef($tempPath); undef($tempName); undef($tempSize); return false; } else { $maxFileLimit = true; } } if ($counter2 > 0) { $option = GetInput("\nWhich files would you like to EXCLUDE (1 or 1-2 or 1,2-3,5)?"); } else { echo "No files > $alertSize..."; } #-------------------------------------------------------- # Parse line that has the files they'd like to include in the download #-------------------------------------------------------- int $selectiveDownloadList; $counter = 0; if ($option == "q") { return true; } else if ($option == "a") { $selectiveDownload = false; } else if ($option == "0") { $selectiveDownload = true; $selectiveDownloadList = $arrayHolder; while ($counter < sizeof($arrayHolder)) { $numberOfFiles--; $totalSize -= $tempSize[$arrayHolder[$counter]]; $selectiveDownloadList[$counter] = $arrayHolder[$counter]; $counter++; } } else { $selectiveDownload = true; string $values = split(",", $option); string $values2; string $value; int $begin; int $end; foreach $value ($values) { $values2 = split("-", $value); $begin = $values2[0]; $begin -= 1; if (defined($values2[1])) { $counter2 = $begin; $end = $values2[1]; $end -= 1; while (($counter2 >= $begin) && ($counter2 <= $end)) { if (defined($arrayHolder[$counter2])) { $numberOfFiles--; $totalSize -= $tempSize[$arrayHolder[$counter2]]; $selectiveDownloadList[$counter] = $arrayHolder[$counter2]; $counter += 1; } $counter2 += 1; } } else { if (defined($arrayHolder[$begin])) { $numberOfFiles--; $totalSize -= $tempSize[$arrayHolder[$begin]]; $selectiveDownloadList[$counter] = $arrayHolder[$begin]; $counter += 1; } } } } undef($arrayHolder); #-------------------------------------------------------- # Sets the throttleing if appropriate #-------------------------------------------------------- if (defined($throttleBytes)) { `throttle -enable $throttleBytes`; } #-------------------------------------------------------- # Run the get statement on all applicable files #-------------------------------------------------------- int $tempList; bool $continue; # Exit if there are no files to download if ($numberOfFiles == 0) { echo "No files match your mask and path..."; return true; } # Make sure the user really wants to continue ifnot (prompt "Really download $numberOfFiles files / $totalSize bytes?") { return true; } if (($selectiveDownload == false) && ($individualFlag == false)) { if ($maxFileLimit) { $dirAndGetFlags = "$dirAndGetFlags -max $numberOfFiles"; } else { $dirAndGetFlags = "$dirAndGetFlags -max 0"; } @echo on; echo "Downloading ALL $fileMask files within given date range (if specified)"; if ($foregroundFlag) { `get $fileMask -path "$directory" $dirAndGetFlags -foreground`; } else { `get $fileMask -path "$directory" $dirAndGetFlags`; `channels`; } } else { int $pauseCounter = 0; int $temp; $counter = 0; $counter2 = 0; int $counter3 = sizeof($tempName); while ($counter < sizeof($tempName)) { $continue = true; # If the user chose to exclude some files...check the exclude list if ($selectiveDownload) { foreach $tempList ($selectiveDownloadList) { if ($counter == $tempList) { $continue = false; break; } } } if ($continue) { # $tempSize = 0 is a directory ifnot ($tempSize[$counter] == 0) { if ($foregroundFlag) { if (`get "$tempPath[$counter]\\$tempName[$counter]" -foreground`) { echo "$numberOfFiles. Downloading \"$tempPath[$counter]\\$tempName[$counter]\" - $tempSize[$counter]"; } else { echo "$numberOfFiles. Downloading \"$tempPath[$counter]\\$tempName[$counter]\" - $tempSize[$counter] - !!! FAILED !!!"; } } else { if (`get "$tempPath[$counter]\\$tempName[$counter]"`) { echo "$numberOfFiles. Downloading \"$tempPath[$counter]\\$tempName[$counter]\" - $tempSize[$counter]"; } else { echo "$numberOfFiles. Downloading \"$tempPath[$counter]\\$tempName[$counter]\" - $tempSize[$counter] - !!! FAILED !!!"; } } # If the user chose to pause after every X downloads if (defined($pauseCount)) { $temp = $counter2; $temp++; $temp %= $pauseCount; if ($temp == 0) { ifnot (prompt "Continue?") { return false; } } } $counter2++; $counter3--; $numberOfFiles--; } } $counter++; } } #-------------------------------------------------------- # Turns off throttleing if apprpriate #-------------------------------------------------------- if (defined($throttleBytes)) { @echo off; `throttle -disable`; } undef($selectiveDownloadList); undef($arrayHolder); undef($tempPath); undef($tempName); undef($tempSize); return true;