wodSFTP --vbs --Retry the Connection (General questions)
I have used the .vbs sample like the following code:
Option Explicit
Dim objFTP, lst
Set objFTP = WScript.CreateObject( WeOnlyDo.wodSFTPCom.1 , wod_ )
' please change these lines, from here
WScript.echo Please edit this file and setup Login, Hostname and Password properties
objFTP.Hostname = put.your.host
objFTP.Login = yourlogin
objFTP.Password = yourpass
' to here
objFTP.Blocking = 1
objFTP.Connect
objFTP.ListDir ( / )
lst = objFTP.ListItem
WScript.echo lst
objFTP.Disconnect
Sub wod_Connected(ErrorCode, ErrorText)
WScript.Echo Connected & ErrorText
End Sub
Sub wod_Disconnected()
WScript.Echo Disconnected
End Sub
The problem is I am trying to Retry the
Connection when the first connect is failing.
What can I do?
Put the Retry code into the 'wod_Connected()' events ?
*either 'on error...'or 'objFTP.LastError' can not get a string representation of the Connected error.
Re: wodSFTP --vbs --Retry the Connection
Hi,
Can you explain it little bit more what is the reason of failing to connect?
So we can exactly help you with your problem.
Regards,
Drazen
Re: wodSFTP --vbs --Retry the Connection
Thank for your fast Reply
The reason of failing to connect is test data.
For Example:
objFTP.Login = LoginId -->User who doesn't exist
objFTP.Password = Password -->Password that doesn't exist
ErrorCode -->30015
ErrorText -->Invalid username or password reported by server.
I wants to make a batch file which can do the following :
If the first Connects to the remote server is failed ,
It will call the second Connection .
Where can I write the code of the 'call the second Connection ' ?
Thanks
Hi,
Can you explain it little bit more what is the reason of failing to connect?
So we can exactly help you with your problem.Regards,
Drazen
Re: wodSFTP --vbs --Retry the Connection
Openpc,
I think this is your choice. Since you are doing this inside VBS and in blocking mode, you could do something like this (pseudo code):
while sftp1.state != connected
sftp1.hostname = something
sftp1.login = something_attempt_1
sftp1.password = something_attempt_1
sftp1.blocking = true
sftp1.connect
wend
above loop will iterate until it connects. Now, it's your job to change Login and Password so they're taken from somewhere and populated each time differently. I don't think you should use events in VBS for this purpose.
Can you try something like that?
Kreso
Re: wodSFTP --vbs --Retry the Connection
Thank you for your help
I rewriting the code like this:
Option Explicit
Dim objFTP, n
Set objFTP = WScript.CreateObject( WeOnlyDo.wodSFTPCom.1 , wod_ )
WScript.echo Please edit this file and setup Login, Hostname and Password properties
n=0
while objFTP.state <> 3 and n < 2
n = n + 1
objFTP.hostname = xxx.xx.x.xxx
objFTP.login = login
objFTP.password = password
objFTP.connect
WScript.Echo objFTP.state: &objFTP.state
WScript.Echo objFTP.LastError: &objFTP.LastError
WScript.Echo objFTP.LastError <> 0: &cstr(objFTP.LastError <> 0)
WScript.Echo objFTP.ErrorText(objFTP.LastError): &objFTP.ErrorText(objFTP.LastError)
wend
WScript.Echo over
1.If the Password doesn't exist ,Execution result like this:
-------Execution result-----------
Please edit this file and setup Login, Hostname and Password properties
objFTP.state:1
objFTP.LastError:30015----->some times it is objFTP.LastError:0
bjFTP.LastError <> 0: True
objFTP.ErrorText(objFTP.LastError):Invalid username or password reported by server.
objFTP.state:1
objFTP.LastError:30015----->some times it is objFTP.LastError:0
bjFTP.LastError <> 0: True
objFTP.ErrorText(objFTP.LastError):Invalid username or password reported by server.
over
----------------------------------
2.If the Password exist ,Execution result like this:
-------Execution result-----------
Please edit this file and setup Login, Hostname and Password properties
objFTP.state:1
objFTP.LastError:0
objFTP.LastError <> 0:false
objFTP.ErrorText(objFTP.LastError):No error
over
----------------------------------
*** if set 'objFTP.blocking = true' ,It will stop by the first Error.
The problem is :
How can I get the 'Error Handling for Connect method' during the 'while.....wend'?
Could I use then 'objFTP.LastError <> 0' to judge the 'Connect' success or failure ?
Thanks
Openpc,
I think this is your choice. Since you are doing this inside VBS and in blocking mode, you could do something like this (pseudo code):
while sftp1.state != connected
sftp1.hostname = something
sftp1.login = something_attempt_1
sftp1.password = something_attempt_1
sftp1.blocking = true
sftp1.connect
wendabove loop will iterate until it connects. Now, it's your job to change Login and Password so they're taken from somewhere and populated each time differently. I don't think you should use events in VBS for this purpose.
Can you try something like that?
Kreso
Re: wodSFTP --vbs --Retry the Connection
So now only missing question is how to handle errors in VBS? If I were you I would ask google about this
http://www.google.com/search?sourceid=navclient&ie=UTF-8&rls=GGLD,GGLD:2005-10,GGLD:en&q=handling+errors+in+vbs
but my first guess would be to set 'on error resume next'.
If I missed the question completely, please rephrase it.
Regards,
Kreso