Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VAL Backup VBScript

Backups

VAL Backup VBScript

by  Ronster  Posted    (Edited  )
This code relies heavily on the posts in this thread: http://www.tek-tips.com/viewthread.cfm?qid=1191903&page=1

It helped me not only to backup my wav files but also learn some VBScript.

So a big thanks to JtheRipper and tsuji.

I added some message box prompts and a case statement to put in the IP address when given the board location. This needs to be coded into the script, but it saves looking up the IP address when you want to backup.

Code:
' valbackup.vbs
' VBScript to Backup VAL Boards.
' Version 1.0 - August 2008
' --------------------------------------
'This script is a combination of a script posted on tek-tips: http://www.tek-tips.com/viewthread.cfm?qid=1191903&page=1
'and another script that I found on the web but couldn't re-find!
' Additional work to make the input and the download parts work together  and some tweaking was carried out by
' Ronnie Cassels.   http://www.linkedin.com/in/ronniecassels

Option Explicit
Dim objFSO, objMyFile, objShell, strFTPScriptFileName, objFolder, strDirectory, outFile, objArgs
Dim strLocalFolderName, strFTPServerName, strLoginID, strFTPServerDir
Dim strPassword, strFTPServerFolder, objPassword, strPath, FolderContent, fso, CleanPath, file, Flag
Dim strMbox, VALIP, VALLogin, VALPwd, VALLoc

strMbox = MsgBox("Do you want to backup your wav files?",4,"VAL Backup")
If strMbox = 6 Then
	strDirectory = InputBox("Enter the name for the new directory:","Set Backup Directory","J:\IT\Voice\Avaya_Backup\VAL_Boards")
Else
	WScript.Quit
End If


' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Note If..Exists. Then, Else ... End If construction
If objFSO.FolderExists(strDirectory) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
   WScript.Echo strDirectory & " already created "
Else
   Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Backup directory created " & strDirectory
End If

[green]'###########################################################################'
'This section will need to be updated with VAL Location and associated IP.
VALLoc = InputBox("Enter the Location of the VAL Board:","VAL Location","04d07")
select case VALLoc 
	Case "03a07"
		VALIP = "170.123.1.136"
	Case "04d07"
		VALIP = "170.123.1.137"
	Case "05a07"
		VALIP = "170.123.1.138"
	Case Else
	msgbox "Unknown VAL Board.  Please edit valftp.vbs to add a new board."
	WScript.Quit
end select
'###########################################################################'[/green]


VALLogin = InputBox("Enter your login for the VAL Board:","VAL Login","")
VALPwd = InputBox("Enter your password for the VAL Board:","VAL Password","")


' Change this, foldername = local dir (where files must be ftp'd TO)
strLocalFolderName = strDirectory

' Server where you are ftp'ing TO
strFTPServerName = VALIP

' Username you use to ftp
strLoginID = VALLogin

' Initialize variables
strPassword = VALPwd
strFTPServerDir = ""

' Change this to the folder where the files are on the source server
'strFTPServerFolder = "/"

'The follow lines of code generate the FTP script file on the fly,
'because the directory name changes every time its run

strFTPScriptFileName = strLocalFolderName & "\FTPScript.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If (objFSO.FileExists(strFTPScriptFileName)) Then
    objFSO.DeleteFile(strFTPScriptFileName)
End If

Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
'objMyFile.WriteLine ("ftp -s open " & strFTPServerName)
'objMyFile.WriteLine ("open " & strFTPServerName)
'objMyFile.WriteLine (strLoginID)

'strPassword = InputBox("Please enter your password:")
'objMyFile.WriteLine (strPassword)

'strFTPServerDir = InputBox("Enter directory from which to ftp:")

objMyFile.WriteLine ("cd " & strFTPServerFolder & strFTPServerDir)
objMyFile.WriteLine ("open " & strFTPServerName)
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
objMyFile.WriteLine ("bin")
objMyFile.WriteLine ("prompt")
objMyFile.WriteLine ("lcd " & strLocalFolderName)
objMyFile.WriteLine ("mget .wav")
objMyFile.WriteLine ("bye")
objMyFile.Close



'The following code executes the FTP script. It creates a Shell
'object and run FTP program on top of it.
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run ("ftp -s:" & chr(34) & strFTPScriptFileName & chr(34)),,True
'objShell.Run (strFTPScriptFileName & chr(34))
Set objShell = Nothing

objFSO.deletefile strFTPScriptFileName,true

Set objFSO = Nothing
Set objMyFile = Nothing


Set fso=CreateObject("Scripting.FileSystemObject")
'CleanPath="c:\temp\test"

For Each file In fso.GetFolder(strLocalFolderName).Files
Flag = StrComp(file, strFTPScriptFileName ,1)
'if Flag = 0 then
'   file.delete
'end if
Next
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top