Function DownloadFtp(strUrl, strLocalFile, strUserName, strPassword) 'As Boolean Dim wsh 'As Wscript.Shell Dim fs 'As Scripting.FileSystemObject Dim tsScript 'As Scripting.TextStream Dim strRemoteSite 'As String Dim strRemoteFile 'As String Dim strScript 'As String Const TemporaryFolder = 2 Const WshHide = 0 Const WshNormalFocus = 1 Const WshMinimizedFocus = 2 Const WshMaximizedNoFocus = 3 Const WshNormalNoFocus = 4 Const WshMinimizedNoFocus = 6 ' Create objects Set wsh = CreateObject("Wscript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") strScript = fs.BuildPath(fs.GetSpecialFolder(TemporaryFolder), fs.GetBaseName(Wscript.ScriptFullName) & ".script") If strUrl = "" Then DownloadFtp = False Exit Function End If If Instr(strUrl, ".") = 0 Then DownloadFtp = False Exit Function End If If Instr(strUrl, "/") = 0 Then DownloadFtp = False Exit Function End If ' Create the local file just so we can get a short name later On Error Resume Next Err.Clear fs.CreateTextFile(strLocalFile, True).Close If Err.Number <> 0 Then DownloadFtp = False Exit Function End If On Error Goto 0 If strUserName = "" Then strUserName = "anonymous" If strPassword = "" Then strPassword = "ieuser@" ' Parse site name strRemoteSite = strUrl If Lcase(Left(strRemoteSite, 6)) = "ftp://" Then strRemoteSite = Mid(strRemoteSite, 7) strRemoteSite = Left(strRemoteSite, Instr(strRemoteSite, "/") - 1) ' Parse file name strRemoteFile = strUrl If Lcase(Left(strRemoteFile, 6)) = "ftp://" Then strRemoteFile = Mid(strRemoteFile, 7) strRemoteFile = Mid(strRemoteFile, Instr(strRemoteFile, "/")) ' Create and run the FTP script Set tsScript = fs.CreateTextFile(strScript, True) tsScript.WriteLine "open " & strRemoteSite tsScript.WriteLine strUserName tsScript.WriteLine strPassword tsScript.WriteLine "hash" tsScript.WriteLine "ascii" tsScript.WriteLine "get " & strRemoteFile & " " & fs.GetFile(strLocalFile).ShortPath tsScript.WriteLine "bye" tsScript.Close Set tsScript = Nothing wsh.Run "%windir%\system32\ftp.exe -s:""" & strScript & """", WshHide, True ' Delete the script as soon as possible because it has the user name and password in clear text fs.DeleteFile strScript ' Delete the local file if we failed to download anything ' FTP may have already deleted it. If fs.FileExists(strLocalFile) Then If fs.GetFile(strLocalFile).Size = 0 Then fs.DeleteFile strLocalFile, True DownloadFtp = False Else DownloadFtp = True End If Else DownloadFtp = False End If End Function