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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBSCRIPT for CuteFTP question. Actually a string to array problem. 1

Status
Not open for further replies.

sparkbyte

Technical User
Sep 20, 2002
879
US
OK, I have seached everywhere I could find in Google and Ask and could come up with one example on Globalscape a short discussion here.

I have the following script that I modified from the example on Globalscape.

Code:
'Declare our variables
Dim YYYY, MM, DD, M, D
Dim fso, tf
Dim MySite
Dim intCurMonth, intCurDay, intCurYear, strCurDate, strCurDate1


' Set Date format for File Downloads
	strCurDate = FormatDateTime(Date(),2)

    intCurMonth = Month(strCurDate)
    If Len(intCurMonth) = 1 Then intCurMonth = "0" & intCurMonth
    intCurDay = Day(strCurDate) - 1 ' subtracting a day for after midnight run time.
    If Len(intCurDay) = 1 Then intCurDay = "0" & intCurDay
    intCurYear = Right(Year(strCurDate),2)

	strCurDate1 = intCurMonth & intCurDay & intCurYear
'	WScript.Echo strCurDate1

'Prepare a consistent YYYY-MM-DD format
YYYY = Year(Date)
M = Month(Date)
if (Len(M)=1) then MM = "0" & M else MM = "" & M
D = Day(Date)
if (Len(D)=1) then DD = "0" & D else DD = "" & D

'Allow for error trapping
On Error Resume Next

'Create the FileSystemObject object and echo failures to the console if run from the command line via
'cscript or to prompts if run interactively
Set fso = CreateObject("Scripting.FileSystemObject")
 If err.Number <> 0 Then
    WScript.Echo (Now & " - Failed to create FileSystem Object!")
    WScript.Echo (Now & " - Description:  " & Err.Description)
    WScript.Echo (Now & " - Error Source: " & Err.Source)
    WScript.Quit(255)
 End If

' Open text file (create if necessary) for writing called something like CuteFTP_2006-03-24.log in C:\'
Set tf = fso.OpenTextFile("E:\CuteFTP_" & YYYY & "-" & MM & "-" & DD & ".log", 8, True)
 If err.Number <> 0 Then
    WScript.Echo (Now & " - Failed to open file for writing!")
    WScript.Echo (Now & " - Description:  " & Err.Description)
    WScript.Echo (Now & " - Error Source: " & Err.Source)
    WScript.Quit(255)
 End If

'Now that this has been successful, we can begin writing lines to our log file

'Create TEConnection object
Set MySite = CreateObject("CuteFTPPro.TEConnection")
If err.Number <> 0 Then
   tf.WriteLine (Now & " - Failed to create TEConnection object!")
   tf.WriteLine (Now & " - Description:  " & Err.Description)
   tf.WriteLine (Now & " - Error Source: " & Err.Source)
   tf.Close
   WScript.Quit(255)
End If

MySite.Host = "192.168.1.100"
MySite.Protocol = "FTP"
MySite.Port = 21
MySite.Retries = 30
MySite.Delay = 30
MySite.MaxConnections = 10
MySite.TransferType = "AUTO"
MySite.DataChannel = "PORT"
MySite.AutoRename = "OFF"
' WARNING!!! SENSITIVE DATA: user name and password.
MySite.Login = "FTPuserID"
MySite.Password = "P@55w0rd"
MySite.SocksInfo = ""
MySite.ProxyInfo = ""



tf.WriteLine (Now & "*********************************************")
tf.WriteLine (Now & " - Connecting...")
MySite.Connect
If err.Number <> 0 Then
    tf.WriteLine (Now & " - Connection Error!")
    tf.WriteLine (Now & " - Description:  " & Err.Description)
    tf.WriteLine (Now & " - Error Source: " & Err.Source)
    tf.WriteLine (Now & " - LOG FOLLOWS:")
    tf.WriteLine MySite.Log
   Else
        tf.WriteLine (Now & " - Connected successfully!")
        tf.WriteLine (Now & " - LOG FOLLOWS:")
        tf.WriteLine MySite.Log
 End If
tf.WriteLine (Now & "********** Start of Tranfer Log ******************")

MySite.RemoteFolder = "/SETL/"
MySite.LocalFolder = "E:\shz"
'arrTemp = MySite.GetList ("","","%NAME")

'WScript.Echo MySite.GetResult
MySite.Download strCurDate1 & ".*"
	If err.Number <> 0 Then
	   tf.WriteLine (Now & " - Failed to transfer File! ")
	   tf.WriteLine (Now & " - Description:  " & Err.Description)
	   tf.WriteLine (Now & " - Error Source: " & Err.Source)
	   tf.Close
	   WScript.Quit(255)
	End If

MySite.Disconnect
tf.WriteLine (Now & "************ End of Log ******************")
tf.Close
MySite.Close "EXITNOPENDING"
WScript.Quit


What I was tryiing to do was add a For Each/Next loop to speed up the transfers and allow for better selection of remote files. The latter being more important.

Here is what I tried.
Code:
' Connect to remote server and get file listing
MySite.Connect

MySite.RemoteFolder = "/SETL/"
MySite.LocalFolder = "s:\"
strResult = MySite.GetList ("","","%NAME")
WScript.Echo strResult

arrTemp = MySite.GetResult
WScript.Echo arrTemp
For Each strTemp In arrTemp
	'MySite.DownloadAsync strTemp
	WScript.Echo strTemp
	WScript.Echo "~~~~~~~~~~~~~~~"
Next
Output said:
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

-1
060307.SETL
060407.CD240R
060407.CD242R
060407.SETL
060407.TD424R
060507.CD240R
060507.CD242R
060507.SETL
060507.TD424R
060607.CD240R
060607.CD242R
060607.SETL
060607.TD424R
060707.CD240R
060707.CD242R
060707.SETL
060707.TD424R
060807.CD240R
060807.SETL
060807.TD424R
060907.CD240R
060907.SETL
060907.TD424R
061007.CD240R
061007.CD242R
061007.SETL
061007.TD424R
061107.CD240R
061107.SETL
061107.TD424R
061207.CD240R
061207.CD242R
061207.SETL
061207.TD424R
061307.CD240R
061307.CD242R
061307.SETL
061307.TD424R


~~~~~~~~~~~~~~~

***** script completed *****

Took me a minute to realize what was happening here. OK, much longer [ponder].

It seems to be outputing the MySite.GetResult as a String result rather than an array. So when I tried to make it an array what I got was an array with 0,0 being the whole list of files.

So, no I am stuck not knowing how to take this string output and convert it into an array.

What I need to be able to do is something lke this.

Code:
For Each strTemp In arrTemp
	If Left(strTemp,6) = strCurDate1 
	Then MySite.DownloadAsync strTemp
	Else 'Skip File
	End If 
Next

Thanks everyone!!!!!



Thanks

John Fuhrman
Titan Global Services
 
Why not using the Split function against the value returned by MySite.GetResult ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How would you use split to split on a carriage return?

arrTemp = Split(MySite.GetResult)

This returns the same result.

Thanks

John Fuhrman
Titan Global Services
 
How would you use split to split on a carriage return?
arrTemp = Split(MySite.GetResult, vbCr)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks,

got it working just as I got your reply.

Now to get it to select only the previous days files.

Thanks!!

Thanks

John Fuhrman
Titan Global Services
 
Oh, and a star. You, tsuji, dm4ever and a few others here at Tek-Tips are one of if not the best VBscript resources on the net!!

Thanks a bunch for all your help.

Thanks

John Fuhrman
Titan Global Services
 
OK, one more question....

why does this work.
Code:
arrTemp = Split(Trim(MySite.GetResult),vbCrLf)
WScript.Echo arrTemp
For Each strTemp In arrTemp
	[!]If (Left(strTemp,7) = strCurDate1) = 0 Then [/!]
	WScript.Echo strTemp
'	 MySite.DownloadAsync strTemp
	Else 'Skip File
	End If 
Next

but not this...
Code:
arrTemp = Split(Trim(MySite.GetResult),vbCrLf)
WScript.Echo arrTemp
For Each strTemp In arrTemp
	[!]If Left(strTemp,7) = strCurDate1 Then [/!]
	WScript.Echo strTemp
'	 MySite.DownloadAsync strTemp
	Else 'Skip File
	End If 
Next

Thanks

John Fuhrman
Titan Global Services
 
I don't think the first work ...
I'd use this:
If Left(strTemp, [!]6[/!]) = strCurDate1 Then


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Strange switched it back to the [!]6[/!] and it started working. I orginaly had it a 6 and it wasn't returning any files.

Thanks!!

Wish you lived in the KC area, would love to meet you some time.

Thanks again.

Thanks

John Fuhrman
Titan Global Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top