Link to home
Start Free TrialLog in
Avatar of AGenMIS
AGenMIS

asked on

Get the date modified of a file on a FTP Site

I am using the below VBScript code to get a file from an FTP site.  However, before I get the file, I'd like to check the file's date modified.  Is there a way to do this?  
Dim objFSO1
Dim objwrc
Dim FileName
Dim objShell, objExecObject, FTPStatus
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
' The Jobs.txt file holds the commands to connect to the ftp server
Set objwrc = objFSO1.CreateTextFile("c:\Jobs.txt", True)
 
' Below is the name of the file we want to copy from the ftp site.
FileName = "MyFile.txt"
' Build the contents of the Jobs.txt file
objwrc.WriteLine "open theftpsite.com"
objwrc.WriteLine "MyUserName"
objwrc.WriteLine "MyPassword"
objwrc.WriteLine "get " & FileName & " C:\MyLocation\" & FileName
objwrc.WriteLine "quit"
Set objShell = CreateObject("WScript.Shell")
objShell.Run "ftp -s:" & "c:\Jobs.txt" & " c:\FTPLog.txt", 0, True
Set objFSO = Nothing
Set objMyFile = Nothing
Set objShell = Nothing
 
MsgBox("Program Complete")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of pilozite
pilozite

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AGenMIS
AGenMIS

ASKER

Thank you for your comment.  It is greatly appreciated.  However, this did not provide me with the date I needed.  Using your code snippet provided me with the date the file was copied to my c:\ drive.  It did not provide me with the date the file had on the FTP server before it was copied.  For example, the file I am copying from the FTP server had the date of 07/15/2009 8:15 AM on the FTP server.  However when I ran your snippet, it provided me with the date of 07/17/2009 10:21 AM.  So you see its giving me the date the file was copied not the actual date on the FTP server.  
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AGenMIS

ASKER

Can this be tweaked to work with VBScript?
<< Can this be tweaked to work with VBScript >>>

No. However if it was compiled as an activex.dll it could be used in VBScript using CreateObject(). I'm not much of a scripting guy so I don't know exactly how one does this using scripts.
Avatar of AGenMIS

ASKER

I'd really like to be able to do this strictly in VBScript.  Any additional help would be appreciated.
Avatar of AGenMIS

ASKER

Is there a way I could use the MDTM command within FTP and capture the output from this command within VBScript?
Avatar of AGenMIS

ASKER

My final solution was to use the following code to capture and process each line of output from the dir command in ftp.

Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objwrc = objFSO1.CreateTextFile("c:\Jobs.txt", True)
objwrc.WriteLine "open theftpsite.com"
objwrc.WriteLine "MyUserName"
objwrc.WriteLine "MyPassWord"
objwrc.WriteLine "dir"
objwrc.WriteLine "quit"
Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("%comspec% /c c:\windows\system32\ftp.exe -s:c:\ Jobs.txt ")
' Process each line of output from the dir commmand
Do While Not objExecObject.StdOut.AtEndOfStream
      strText = objExecObject.StdOut.ReadLine()
      'I have complex string manipulation to grab the date info from the dir output here.
Loop
Avatar of AGenMIS

ASKER

pilozite and egl1044 thank you for your input.  My final solution can be seen in my comments.  Again, thanks for the input.