jonathanduane2010
asked on
getting script to run every hour
hi,
i have this script and i was wondering if there was a way to have it running every hour?
'------------------------- ---------- ---------- ---------- ---------- ---------- ---
Const appName = "FTP Upload Utility"
'------------------------- ---------- ---------- ---------- ---------- ---------- ---
Const Hostname = "myhostname"
Const Port = 21
Const Username = "myusername"
Const Password = "xxxxxxxxx"
Const RemoteDir = "/fm104"
Const strExt = "mp3"
Const LocalDir = "c:\mp3"
Const MaxAge = 10
SET objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set ObjFolder = objFSO.GetFolder(LocalDir)
FOR EACH objFile in ObjFolder.Files
if RIGHT(UCASE(objFile.Path), LEN(strExt )+1) = "." & strExt then
if datediff("s", objFile.DateLastModified, Now) > 40 Then
Upload hostname, port, username, password, objFile.Name, localDir, remoteDir
'objFile.Delete
End If
End If
Next
'------------------------- ---------- ---------- ---------- ---------- ---------- ---
Sub Upload(hostname, port, username, password, localFile, localDir, remoteDir)
Set shell = CreateObject( "WScript.Shell" )
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
tempDir = shell.ExpandEnvironmentStr ings("C:\t emp")
' temporary script file supplied to Windows FTP client
scriptFile = tempDir & "\" & fso.GetTempName
' temporary file to store standard output from Windows FTP client
outputFile = tempDir & "\" & fso.GetTempName
'input script
script = script & "lcd " & """" & localDir & """" & vbCRLF
script = script & "open " & hostname & " " & port & vbCRLF
script = script & "user " & username & vbCRLF
script = script & password & vbCRLF
script = script & "cd " & """" & remoteDir & """" & vbCRLF
script = script & "binary" & vbCRLF
script = script & "prompt n" & vbCRLF
script = script & "put " & """" & localFile & """" & vbCRLF
script = script & "quit" & vbCRLF
Set textFile = fso.CreateTextFile(scriptF ile, True)
textFile.WriteLine(script)
textFile.Close
Set textFile = Nothing
' bWaitOnReturn set to TRUE - indicating script should wait for the program
' to finish executing before continuing to the next statement
shell.Run "%comspec% /c FTP -n -s:" & scriptFile & " > " & outputFile, 0, TRUE
Wscript.Sleep 500
' open standard output temp file read only, failing if not present
Set textFile = fso.OpenTextFile(outputFil e, 1, 0, -2)
If Not textFile.AtEndOfStream Then
Results = textFile.ReadAll
End If
textFile.Close
If InStr(results, "550") > 0 And (InStr(results, "226") or Instr(results, "221")) Then
fso.DeleteFile(scriptFile)
fso.DeleteFile(outputFile)
'Msg ="WARNING: Could not change to destination directory on host!" & _
' vbCRLF & "File however appears to have been uploaded to default " & _
' "FTP directory associated with user on host."
'MsgBox Msg, vbExclamation, appName
ElseIf (InStr(results, "226") or Instr(results, "221")) > 0 Then
'MsgBox "File Uploaded Successfully.", vbInformation, appName
fso.DeleteFile(scriptFile)
fso.DeleteFile(outputFile)
Else
If InStr(results, "530") > 0 Then
'Msg ="ERROR: Invalid Username/Password"
ElseIf InStr(results, "550") > 0 Then
'Msg ="ERROR: Could not change to destination directory on host"
ElseIf InStr(results, "553") > 0 Then
'Msg ="ERROR: Could not create file on host"
ElseIf InStr(results, "Unknown host") > 0 Then
'Msg ="ERROR: Unknown host"
ElseIf InStr(results, "File not found") > 0 Then
'Msg ="ERROR: Local File Not Found"
Else
'Msg ="An ERROR may have occurred."
End If
'Msg = Msg & _
' vbCRLF & "Script file leveraged: " & scriptFile & _
' vbCRLF & "FTP Output file: " & outputFile & _
' vbCRLF & _
' vbCRLF & "Ensure the above files are manually deleted, as they may " & _
' "contain sensitive information!"
'MsgBox Msg, vbCritical, appName
End If
Set shell = Nothing
Set fso = Nothing
End Sub
i have this script and i was wondering if there was a way to have it running every hour?
'-------------------------
Const appName = "FTP Upload Utility"
'-------------------------
Const Hostname = "myhostname"
Const Port = 21
Const Username = "myusername"
Const Password = "xxxxxxxxx"
Const RemoteDir = "/fm104"
Const strExt = "mp3"
Const LocalDir = "c:\mp3"
Const MaxAge = 10
SET objFSO = CreateObject("Scripting.Fi
Set ObjFolder = objFSO.GetFolder(LocalDir)
FOR EACH objFile in ObjFolder.Files
if RIGHT(UCASE(objFile.Path),
if datediff("s", objFile.DateLastModified, Now) > 40 Then
Upload hostname, port, username, password, objFile.Name, localDir, remoteDir
'objFile.Delete
End If
End If
Next
'-------------------------
Sub Upload(hostname, port, username, password, localFile, localDir, remoteDir)
Set shell = CreateObject( "WScript.Shell" )
Set fso = CreateObject("Scripting.Fi
tempDir = shell.ExpandEnvironmentStr
' temporary script file supplied to Windows FTP client
scriptFile = tempDir & "\" & fso.GetTempName
' temporary file to store standard output from Windows FTP client
outputFile = tempDir & "\" & fso.GetTempName
'input script
script = script & "lcd " & """" & localDir & """" & vbCRLF
script = script & "open " & hostname & " " & port & vbCRLF
script = script & "user " & username & vbCRLF
script = script & password & vbCRLF
script = script & "cd " & """" & remoteDir & """" & vbCRLF
script = script & "binary" & vbCRLF
script = script & "prompt n" & vbCRLF
script = script & "put " & """" & localFile & """" & vbCRLF
script = script & "quit" & vbCRLF
Set textFile = fso.CreateTextFile(scriptF
textFile.WriteLine(script)
textFile.Close
Set textFile = Nothing
' bWaitOnReturn set to TRUE - indicating script should wait for the program
' to finish executing before continuing to the next statement
shell.Run "%comspec% /c FTP -n -s:" & scriptFile & " > " & outputFile, 0, TRUE
Wscript.Sleep 500
' open standard output temp file read only, failing if not present
Set textFile = fso.OpenTextFile(outputFil
If Not textFile.AtEndOfStream Then
Results = textFile.ReadAll
End If
textFile.Close
If InStr(results, "550") > 0 And (InStr(results, "226") or Instr(results, "221")) Then
fso.DeleteFile(scriptFile)
fso.DeleteFile(outputFile)
'Msg ="WARNING: Could not change to destination directory on host!" & _
' vbCRLF & "File however appears to have been uploaded to default " & _
' "FTP directory associated with user on host."
'MsgBox Msg, vbExclamation, appName
ElseIf (InStr(results, "226") or Instr(results, "221")) > 0 Then
'MsgBox "File Uploaded Successfully.", vbInformation, appName
fso.DeleteFile(scriptFile)
fso.DeleteFile(outputFile)
Else
If InStr(results, "530") > 0 Then
'Msg ="ERROR: Invalid Username/Password"
ElseIf InStr(results, "550") > 0 Then
'Msg ="ERROR: Could not change to destination directory on host"
ElseIf InStr(results, "553") > 0 Then
'Msg ="ERROR: Could not create file on host"
ElseIf InStr(results, "Unknown host") > 0 Then
'Msg ="ERROR: Unknown host"
ElseIf InStr(results, "File not found") > 0 Then
'Msg ="ERROR: Local File Not Found"
Else
'Msg ="An ERROR may have occurred."
End If
'Msg = Msg & _
' vbCRLF & "Script file leveraged: " & scriptFile & _
' vbCRLF & "FTP Output file: " & outputFile & _
' vbCRLF & _
' vbCRLF & "Ensure the above files are manually deleted, as they may " & _
' "contain sensitive information!"
'MsgBox Msg, vbCritical, appName
End If
Set shell = Nothing
Set fso = Nothing
End Sub
Just schedule a Windows task to run everyhour.
I don't know wich version of Windows you have.
If it's XP:
http://support.microsoft.com/kb/308569
If it's Windows 7:
http://windows.microsoft.com/en-US/windows7/schedule-a-task
jppinto
If it's XP:
http://support.microsoft.com/kb/308569
If it's Windows 7:
http://windows.microsoft.com/en-US/windows7/schedule-a-task
jppinto
BTW have posted a requestattention to have your password removed from script.... was able to logon :-)
ASKER
thank you so much!
i dunno what i was thinking!
i dunno what i was thinking!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.