Support
Dedicated Knowledge Base
Article | 207 | |
Title | VBScript to FTP get | |
Content |
' ftp_get.vbs ' file transfer get w/ weekday rotate if zip Option Explicit Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim arg Dim sh Dim fso Dim sHost Dim sUser Dim sPass Dim sFile Dim sFileRem Dim sFileLoc Dim sFolder Dim sCmd Dim sFtp Dim iRtn Set arg = WScript.Arguments Set sh = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") If arg.Count < 5 Then WScript.Echo "arg.Count < 5" WScript.Quit(0) Else sHost = arg.Item(0) sUser = arg.Item(1) sPass = arg.Item(2) sFileRem = arg.Item(3) sFileLoc = Replace(arg.Item(4), ".zip", "_" & Weekday(Now) & ".zip") sFtp = "open " & sHost & vbCrLf sFtp = sFtp & "user" & vbCrLf sFtp = sFtp & sUser & vbCrLf sFtp = sFtp & sPass & vbCrLf sFtp = sFtp & "binary" & vbCrLf sFtp = sFtp & "get " & sFileRem & " " & sFileLoc & vbCrLf sFtp = sFtp & "quit" & vbCrLf sFile = "\temp\ftp" & Int((60 * 60 * 24 * Rnd) + 1) & ".scr" Call WriteFile(sFile, sFtp) sCmd = "ftp -n -i -s:" & sFile iRtn = sh.Run(sCmd, 1, true) ' If fso.FileExists(sFile) Then fso.DeleteFile(sFile) End If WScript.Quit(0) Sub WriteFile(vsFile, vsContent) Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fso Dim f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(vsFile, ForWriting, True) f.Write(vsContent) f.Close Set fso = Nothing Set f = Nothing End Sub | |
Modified Date | 9/16/2006 |