Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get DateLastModified and ProductVersion from FTP location

Status
Not open for further replies.

pork1977

Technical User
Feb 15, 2006
20
0
0
GB
Hi there,

I'm wondering if this is possible... I'm hoping to use this as part of a custom action within an InstallShield solution if so.

So at the moment I have the following vbscript which basically does 2 things for me...
The first part looks at a folder path on the network and then gets the most recent subfolder within it by checking DateLastModified, the folder name is then put into a variable called 'LastFolder'
The second part will look at a file called Setup.exe and get the ProductVersion from it, also put into a variable called 'ProductVersion'
Then it just echoes these variables so I can check if they are correct or not.

What I would like to know, is this:

"If the folder path was, say at a FTP location, so "\\servername\releases\example folder" was something like "ftp://username:password@ftp.example.com/example folder"
and I wanted the script to act in the same way, what do I need to change in the example below to make it function correctly?"

I've been searching the internet today just trying to find some simple examples of how I might even begin, but I haven't had much luck and I'm not the greatest when it comes to creating these sorts of scripts, so I thought I might ask here to see if anyone could help at all.

Thank you.
Paul


'First section gets the most recent subfolder (last modified) from the Releases folder

Set fs = CreateObject("Scripting.FileSystemObject")
Set MainFolder = fs.GetFolder("\\servername\releases\product name")
For Each fldr In MainFolder.SubFolders
''As per comment
If fldr.DateLastModified > LastDate Or IsEmpty(LastDate) Then
LastFolder = fldr.Name
LastDate = fldr.DateLastModified
End If
Next


'Second section gets the product version information from Setup.exe

strPath = ""+MainFolder+"\"+LastFolder+""
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strPath)
Dim arrHeaders(301)

For i = 0 to 300
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next

For Each strFName in objFolder.Items
If strFName = "Setup.exe" Then
For i = 0 to 300
If LCase(arrHeaders(i)) = "product version" Then ProductVersion = objFolder.GetDetailsOf(strFName, i)
Next
End If
Next

'Sets the MSI properties to be used in the LaunchNewerSetup custom action
'session.property("PRODUCT_VERSION") = ProductVersion
'session.property("SETUP_PATH") = strPath

WScript.Echo strPath
WScript.Echo ProductVersion

 
Edited a section: (see below)

so "\\servername\releases\example folder" was something like "[ignore]ftp://username:password@ftp.example.com/example folder"[/ignore]
 
To complete this thread, I found there was no easy way to do what I wanted, I came up with the below script though so thought I'd post here to help others.
I'm sure there's lots of ugly things in this script which more experienced guys will notice, like duplication of parts which might not necessarily need to be there, if anyone could clean it up then that would be most appreciated as I'd probably learn something in the process. Thanks again.


'Set variables

set objFSO = CreateObject("Scripting.FileSystemObject")
CurrentDirectory = objFSO.GetAbsolutePathName(".")
FileName = "Setup.exe"
FTPHost = "1.1.1.1"
USER = "Administrator"
PSWD = "**********"



'Reads list of directories from FTP site and puts output into FileList.txt file

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objwrc = objFSO.CreateTextFile(""+CurrentDirectory+"\Jobs.txt", True)
dtmToday = Date()

objwrc.WriteLine "open "+FTPHost+""
objwrc.WriteLine ""+USER+""
objwrc.WriteLine ""+PSWD+""
objwrc.WriteLine "cd ""IntefleCS DMS"""
objwrc.WriteLine "ls"
objwrc.WriteLine "quit"

Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec _
("%comspec% /c c:\windows\system32\ftp.exe -s:"+CurrentDirectory+"\Jobs.txt | FIND /V ""User"" | FIND /V ""cd"" | FIND /V ""ls"" | FIND /V ""quit"" >"+CurrentDirectory+"\FileList.txt")

Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
Loop





'Removes the remaining carrage returns at the end of FileList.txt file

Set objDictionary = CreateObject("Scripting.Dictionary")

Const ForReading = 1
Const DeleteReadOnly = True
Const ForWriting = 2
Set objFile = objFSO.OpenTextFile (""+CurrentDirectory+"\FileList.txt", ForReading)

strFile = objFile.ReadAll
objFile.Close

intLength = Len(strFile)
strEnd = Right(strFile, 2)

If strEnd = vbCrLf Then
strFile = Left(strFile, intLength - 7)
Set objFile = objFSO.OpenTextFile(""+CurrentDirectory+"\FileList.txt", ForWriting)
objFile.Write strFile
objFile.Close
End If





' Reads FileList.txt, puts last line into variable called LastFolder

Set objFile = objFSO.OpenTextFile (""+CurrentDirectory+"\FileList.txt", ForReading)

i = 0
Do Until objFile.AtEndOfStream
strNextLine = objFile.Readline

If strNextLine <> "" Then
objDictionary.Add i, strNextLine
End If

i = i + 1
Loop
objFile.Close

For Each strLine in objDictionary.Items
LastFolder = strLine
Next

MsgBox ("Most recent subfolder should be "+LastFolder+"")





'Downloads Setup.exe from the FTP site, it uses the variable LastFolder from above so it knows the latest version

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objwrc = objFSO.CreateTextFile(""+CurrentDirectory+"\Jobs2.txt", True)
dtmToday = Date()

objwrc.WriteLine "open "+FTPHost+""
objwrc.WriteLine ""+USER+""
objwrc.WriteLine ""+PSWD+""
objwrc.WriteLine "cd ""IntefleCS DMS\"+LastFolder+""""
objwrc.WriteLine "get "&FileName
objwrc.WriteLine "quit"

Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec _
("%comspec% /c c:\windows\system32\ftp.exe -s:"+CurrentDirectory+"\Jobs2.txt")

Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()

If Instr(strText, "cannot find") > 0 Then
FTPStatus = " download failed"
Else
FTPStatus = " has been downloaded"
End If
Loop
objFile.Close
objwrc.Close





'Clean up txt files

objFSO.DeleteFile(""+CurrentDirectory+"\FileList.txt"),DeleteReadOnly
objFSO.DeleteFile(""+CurrentDirectory+"\Jobs.txt"),DeleteReadOnly
objFSO.DeleteFile(""+CurrentDirectory+"\Jobs2.txt"),DeleteReadOnly





'Gets the product version information from Setup.exe

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(CurrentDirectory)
Dim arrHeaders(301)

For i = 0 to 300
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next

For Each strFName in objFolder.Items
If strFName = "Setup.exe" Then
For i = 0 to 300
If LCase(arrHeaders(i)) = "product version" Then ProductVersion = objFolder.GetDetailsOf(strFName, i)
Next
End If
Next

Const bytesToKb = 1024
Set objFSO = createobject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(""+CurrentDirectory+"\"+Filename+"")
Size = objFile.Size\1024\1024

'Sets the MSI properties to be used in the LaunchNewerSetup custom action
'session.property("PRODUCT_VERSION") = ProductVersion
'session.property("SETUP_PATH") = CurrentDirectory
'session.property("FILE_SIZE") = Size

MsgBox ("FilePath: "+CurrentDirectory+", product version of Setup.exe: "+ProductVersion+"")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top