CODE
----------------------------------------------------------------------------------------------------------
-- Name: Ftptest.lua
-- Author: Intellipool AB
-- Version: 2.0
-- Date: 2006-02-16
-- Description: The script connects to a FTP server and checks if a file exists
-- it can optionaly validate the size of the file.
-- Arguments:
-- Username
-- Password
-- FTP Port number
-- File name
-- Min size in bytes (optional)
----------------------------------------------------------------------------------------------------------
iArgumentCount = GetArgumentCount()
if iArgumentCount < 5 then
SetExitStatus("To few arguments",false)
return
end
ftp = TLuaFTPClient:new();
-- Enter the username and password for the session
sUsername = GetArgument(0)
sPassword = GetArgument(1)
iPort = tonumber(GetArgument(2))
sFilename = GetArgument(3)
iMinSize = -1
if iArgumentCount > 4 then
iMinSize = tonumber(GetArgument(4))
end
-- Connect to FTP server using username and password
iRet = ftp:Connect(sUsername,sPassword,iPort)
-- Check return value from server
if iRet == 0 then
-- Failed to connect, print why
iRet = GetLastError()
sErrorString = FormatErrorString(iRet)
sError = "Error when connecting to FTP server, error: "..sErrorString
SetExitStatus(sError,false);
ftp:Close()
else
-- Check size if needed
iSize = ftp:GetFileSize(sFilename);
print("Size"..iSize)
if iMinSize ~= -1 then
-- File found, check if its less then specified
if iSize < iMinSize then
SetExitStatus("File less then specifed size",false)
ftp:Close()
return
end
SetExitStatus("Test ok",true);
ftp:Close()
else
-- File not found
if iSize == -1 then
SetExitStatus("File does not exsist",false)
ftp:Close()
return
end
SetExitStatus("Test ok",true);
ftp:Close()
end
end
ftp:Close()
-- Name: Ftptest.lua
-- Author: Intellipool AB
-- Version: 2.0
-- Date: 2006-02-16
-- Description: The script connects to a FTP server and checks if a file exists
-- it can optionaly validate the size of the file.
-- Arguments:
-- Username
-- Password
-- FTP Port number
-- File name
-- Min size in bytes (optional)
----------------------------------------------------------------------------------------------------------
iArgumentCount = GetArgumentCount()
if iArgumentCount < 5 then
SetExitStatus("To few arguments",false)
return
end
ftp = TLuaFTPClient:new();
-- Enter the username and password for the session
sUsername = GetArgument(0)
sPassword = GetArgument(1)
iPort = tonumber(GetArgument(2))
sFilename = GetArgument(3)
iMinSize = -1
if iArgumentCount > 4 then
iMinSize = tonumber(GetArgument(4))
end
-- Connect to FTP server using username and password
iRet = ftp:Connect(sUsername,sPassword,iPort)
-- Check return value from server
if iRet == 0 then
-- Failed to connect, print why
iRet = GetLastError()
sErrorString = FormatErrorString(iRet)
sError = "Error when connecting to FTP server, error: "..sErrorString
SetExitStatus(sError,false);
ftp:Close()
else
-- Check size if needed
iSize = ftp:GetFileSize(sFilename);
print("Size"..iSize)
if iMinSize ~= -1 then
-- File found, check if its less then specified
if iSize < iMinSize then
SetExitStatus("File less then specifed size",false)
ftp:Close()
return
end
SetExitStatus("Test ok",true);
ftp:Close()
else
-- File not found
if iSize == -1 then
SetExitStatus("File does not exsist",false)
ftp:Close()
return
end
SetExitStatus("Test ok",true);
ftp:Close()
end
end
ftp:Close()