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")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
I'd really like to be able to do this strictly in VBScript. Any additional help would be appreciated.
ASKER
Is there a way I could use the MDTM command within FTP and capture the output from this command within VBScript?
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.Fi leSystemOb ject")
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.Shel l")
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.AtEnd OfStream
strText = objExecObject.StdOut.ReadL ine()
'I have complex string manipulation to grab the date info from the dir output here.
Loop
Set objFSO1 = CreateObject("Scripting.Fi
Set objwrc = objFSO1.CreateTextFile("c:
objwrc.WriteLine "open theftpsite.com"
objwrc.WriteLine "MyUserName"
objwrc.WriteLine "MyPassWord"
objwrc.WriteLine "dir"
objwrc.WriteLine "quit"
Set objShell = CreateObject("WScript.Shel
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.AtEnd
strText = objExecObject.StdOut.ReadL
'I have complex string manipulation to grab the date info from the dir output here.
Loop
ASKER
pilozite and egl1044 thank you for your input. My final solution can be seen in my comments. Again, thanks for the input.
ASKER