AutoPlay Media Studio 9

FTPWI.GetFileSize

FTPWI.GetFileSize

This is the first topic This is the last topic  

FTPWI.GetFileSize

This is the first topic This is the last topic  

OverviewExamples

number FTPWI.GetFileSize (

string   URL,

string   Username = "anonymous",

string   Password = "guest@",

number   Mode = MODE_BINARY,

number   Timeout = 20,

number   Port = 21,

boolean PassiveMode = true,

function CallbackFunction = nil )

Example 1

nFileSize = FTPWI.GetFileSize("ftp://ftp.myftpsite.com/myfile.txt", "anonymous", "guest@", MODE_BINARY, 20, 21, true, nil);

Gets the size of the file "myfile.txt" and stores the result in nFileSize.

Example 2

-- Settings for FTPWI actions

sFileOnServer = "ftp://ftp.myftpsite.com/myfile.exe";

sLocalFilePath = _TempFolder .. "\\myfile.exe";

sServerUser = "anonymous";

sServerPass = "guest@";

nServerMode = MODE_BINARY;

nServerTimeout = 20;

nServerPort = 21;

bUsePassive = true;

 

-- Set the max bytes allowed without alerting the user to 2MB (2*1024*1024):

QuestionByteThreshold = 2097152;

 

-- Assume download should continue

bContinueDownload = true;

 

-- Get size of file to be downloaded

FileSize = FTPWI.GetFileSize(sFileOnServer, sServerUser, sServerPass, nServerMode, nServerTimeout, nServerPort, bUsePassive, nil);

 

-- Check if filesize is unknown

if FileSize == -1 then

 

   -- Filesize is unknown, alert user

   choice = Dialog.Message("Alert", "Filesize is unknown. Continue Download?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);

   if choice == 7 then

       -- User chose not to continue with download

       bContinueDownload = false;

   end

 

   -- Check if filesize is greater than threshold

elseif FileSize > QuestionByteThreshold then

   -- Filesize is larger than threshold, alert the user

  choice = Dialog.Message("Alert", "Filesize is greater than the threshold by " .. FileSize - QuestionByteThreshold .. " bytes.  Continue Download?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);

   if choice == 7 then

       -- User chose not to continue with download

       bContinueDownload = false;

   end

end

 

 

-- Check if download should continue

if bContinueDownload then

   -- Download File

   FTPWI.Download(sFileOnServer, sLocalFilePath, sServerUser, sServerPass, nServerMode, nServerTimeout, nServerPort, bUsePassive, nil);

else

   -- Don't download file, alert user that download has been terminated

   Dialog.Message("Alert", "Download aborted by user");

end

Checks the size of a file on an FTP server to be downloaded.  If the file is larger than a predefined threshold, the user is asked if the download should continue.

See also: Related Actions


Learn More: Indigo Rose Software - AutoPlay Media Studio - Buy Now - Contact Us