×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Get DateLastModified and ProductVersion from FTP location

Get DateLastModified and ProductVersion from FTP location

Get DateLastModified and ProductVersion from FTP location

(OP)
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 "password@ftp.example.com/example" target="_blank">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

RE: Get DateLastModified and ProductVersion from FTP location

(OP)
Edited a section: (see below)

so "\\servername\releases\example folder" was something like "ftp://username:password@ftp.example.com/example folder"

RE: Get DateLastModified and ProductVersion from FTP location

(OP)
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+"")

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close