/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////// FTP Get Script and save as Stored Script /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Imports System.IO @SCRIPTNAME = "TREAS_AP_DAILY" Dim strIPAddress As String = "122.201.87.43" Dim strCommand As String = "FTP -s:" ExecSql.DefineDateTime(@DATETIME) @DATETIME = ExecSQL.Now ExecSQL.DefineDate(@DATE) @DATE = ExecSQL.Today ExecSQL.DefineTime(@TIME) @TIME = ExecSQL.Time /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Get version of Application /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Dim loVersionInfo As T1.Tb.VersionInfo.VersionInfo = T1.Tb.VersionInfo.VersionInfo.CurrentInstance() Dim loProductVersion as string = loVersionInfo.ProductVersion ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Get set to Run appropriate FTP Script using version information from above ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Dim strGetTreasuryScriptPath As String = "C:\T1\fin1\data\cisaledemo113\TreasuryScripts\" //Batch File Path Dim strScriptFile As String = "" Select Case Mid(loProductVersion,1,5) Case "10.02": strScriptFile = strGetTreasuryScriptPath & "10.02GetTreasuryDailyScript.bat" Case "11.01": strScriptFile = strGetTreasuryScriptPath & "11.01GetTreasuryDailyScript.bat" Case "11.02": strScriptFile = strGetTreasuryScriptPath & "11.02GetTreasuryDailyScript.bat" Case "11.03": strScriptFile = strGetTreasuryScriptPath & "11.03GetTreasuryDailyScript.bat" Case "11.04": strScriptFile = strGetTreasuryScriptPath & "11.04GetTreasuryDailyScript.bat" Case "11.05": strScriptFile = strGetTreasuryScriptPath & "11.05GetTreasuryDailyScript.bat" Case "11.06": strScriptFile = strGetTreasuryScriptPath & "11.06GetTreasuryDailyScript.bat" Case "11.07": strScriptFile = strGetTreasuryScriptPath & "11.07GetTreasuryDailyScript.bat" End Select /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Download appropriate script file /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Shell(strCommand & strScriptFile & " " & strIPAddress, 1, True) //Shell out, run batch file, then return here. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Open Script file and save as stored script in Technology One Application ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Validate File Exists, if not report & exit /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// If (My.Computer.FileSystem.FileExists(strGetTreasuryScriptPath & "DailyScript.txt") = True) Then /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Access File for Reading /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Dim fs As New FileStream(strGetTreasuryScriptPath & "DailyScript.txt", FileMode.Open,FileAccess.Read) Dim buffer() As Byte ReDim buffer(fs.Length - 1) For i As int32 = 0 To Buffer.Length - 1 Buffer(i) = fs.ReadByte() Next fs.Close() /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Get the string Length of the script /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Dim intLen As Integer = Buffer.Length - 1 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Break Script into Characters /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Dim strToken(intLen) As String Dim intCount As Integer = 0 Dim intX As Integer = 0 //Just Add everything at this stage. If line feed found append carriage return For intCount = 1 to intLen strToken(intCount) = Chr(buffer(intCount)) //StatLog.Write("Character found = Chr(" & ASC(strToken(intCount)) & ") representing ASCII Character '" & Chr(buffer(intCount)) & "'") Next intCount Dim intSegments As Integer = 0 intSegments = intLen / 250 If intLen MOD 250 <> 0 Then intSegments = intSegments + 1 End If /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Tokenize Script /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Dim strSegment(intSegments) As String Dim intStart As Int16 = 0 Dim intEnd As Int16 = 0 intCount = 0 For intCount = 1 to intSegments //Calculate starting point in buffer If intCount = 1 Then intStart = intCount Else intStart = (intCount - 1) * 250 End If //Calculate end point of buffer intEnd = intStart + 250 If intEnd > intLen Then intEnd = intLen End If //Get String Segment For intX = intStart to intEnd strSegment(intCount) = strSegment(intCount) & strToken(intX) Next intX //Add the 251st Character (T1 requirement) strSegment(intCount) = strSegment(intCount) & "X" //Check its working properly? //StatLog.Write(CStr(intCount) & ". " & strSegment(intCount) & vbNewLine) Next intCount Dim intCounter As Integer = 0 ExecSQL.Begin SELECT MAX(vers) + 1 AS VERSION FROM tbssp_scripts_ctl WHERE script_name = @SCRIPTNAME AND script_owner_userid = 'SYSTEM' ExecSQL.End ExecSQL.Commit @VERS = ExecSQL.Value("VERSION", 1) @LASTVERS = @VERS - 1 ExecSQL.Begin UPDATE tbssp_scripts_ctl SET script_descr = 'Test Shell to FTP from stored script', template_ind = 'N', tmplt_name = '', tmplt_grp_seqnbr = 0, tmplt_grp = '', techone_fld1 = '2', techone_fld2 = '2', script_type = 'GENERAL', last_mod_user = 'TECHONE', last_mod_datei = @DATE, last_mod_timei = @TIME, last_mod_term = '', last_mod_window = 'TBSSP100', vers = @VERS WHERE script_name = @SCRIPTNAME AND script_owner_userid = 'SYSTEM' AND vers = @LASTVERS ExecSQL.End ExecSQL.Commit ExecSQL.Begin DELETE FROM tbssp_scripts_det WHERE script_name = @SCRIPTNAME AND script_owner_userid = 'SYSTEM' ExecSQL.End ExecSQL.Commit For intCounter = 1 to intSegments @SEQNBR = intCounter @SCRIPTSEGMENT = strSegment(intCounter) ExecSQL.Begin INSERT INTO tbssp_scripts_det(script_name, script_owner_userid, script_seqnbr, script_detail, vers) VALUES (@SCRIPTNAME,'SYSTEM',@SEQNBR,@SCRIPTSEGMENT,@VERS) ExecSQL.End ExecSQL.Commit Next intCounter ExecSQL.Begin SELECT 1 FROM tbcac_cache_dates WHERE Cache_name = 'T1.Tb.Ssp.Script' AND Cache_item = 'ALL' AND user_id = 'ALL' ExecSQL.End ExecSQL.Commit ExecSQL.Begin UPDATE tbcac_cache_dates SET last_mod_datei = @DATETIME, vers = @VERS WHERE Cache_name = 'T1.Tb.Ssp.Script' AND Cache_item = 'ALL' AND user_id = 'ALL' ExecSQL.End ExecSQL.Commit Else StatLog.Write("No Files matching your requirements found in this directory. Aborting script!") Stop Processing //Abort Script End If