Monday, July 20, 2009 1:54 PMI 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? Could I perhaps somehow use the MDTM command within FTP and capture the output of this command in VBScript?
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")
Monday, July 20, 2009 4:12 PMModeratorHi AGJOHN55,
You posted the same question in an earlier thread already...
Here is part of my response from the above post:
Alternatively, you could use the ftp client program, issue a 'dir' on the remote system followed by 'quit', write the output to a file, and parse the file. (But again, the file's reported timestamp may depend on the remote server and how the ftp utility reports file timestamps.)
- Marked As Answer by AGJOHN55 Wednesday, July 22, 2009 12:17 PM
Tuesday, July 21, 2009 6:49 PM
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"
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.
- Marked As Answer by AGJOHN55 Tuesday, July 21, 2009 6:49 PM
Tuesday, July 21, 2009 8:25 PMModeratorHi AGJOHN55,
Great, glad to hear you came up with a solution.