Information générale
Catégorie:
Contrôles ActiveX en VFP
Hi David,
My test codes (I created a form with the MSINET.OCX in it):
------------------------------------------------------------------------
DO FORM WebCtrl NAME oWebCtrl NOSHOW
oWebCtrl.Protocol = 2 && FTP
oWebCtrl.RemotePort = 21
owebCtrl.Logfile = "webftp.log"
oWebCtrl.RemoteHost = "abc.pacific.net"
oWebCtrl.RemotePath = "/22/userid/public_html"
oWebCtrl.Username = "userid"
oWebCtrl.Password = "password"
oWebCtrl.Proxy = ""
oWebCtrl.Manual = .T.
oWebCtrl.Visible = .T.
oWebCtrl.btnClose.Enabled = oWebCtrl.Manual
IF (oWebCtrl.ErrorNo == 0) .AND. (oWebCtrl.InetCtrl.ResponseCode == 0)
oWebCtrl.ExecCmd("SEND 08171.html /22/userid/public_html/08171.html")
ENDIF
------------------------------------------------------------------------
Form ExecCmd Method has the following codes:
------------------------------------------------------------------------
LPARAMETERS cCmd
IF !Thisform.inetctrl.StillExecuting
Thisform.writelnlog(cCmd)
Thisform.inetctrl.Execute(,cCmd)
Thisform.WaitResponse()
ELSE
Thisform.writelnlog("Hang On ... I am Still Busy...")
ENDIF
------------------------------------------------------------------------
Form WaitResponse() Method has the following codes:
------------------------------------------------------------------------
LPARAMETERS nTimeOut
LOCAL lTimeOut
lTimeOut = .F.
nTimeOut = IIF(VARTYPE(nTimeOut)=="N",nTimeOut,Thisform.InetCtrl.RequestTimeOut)
_VFP.AutoYield = .F.
*!* Thisform.writelnlog("Timeout:"+TRANSFORM(nTimeOut))
*!* Thisform.writelnlog("Timer:"+TRANSFORM(Thisform.txtTimer.Value))
DO WHILE !Thisform.txtDone.Value ;
.AND. (Thisform.ErrorNo == 0) ;
.AND. (Thisform.InetCtrl.ResponseCode == 0)
DOEVENTS
IF Thisform.txtTimer.Value >= nTimeOut
lTimeOut = .T.
EXIT
ENDIF
ENDDO
_VFP.AutoYield = .T.
*!* Thisform.writelnlog("TimeOut? "+TRANSFORM(lTimeOut))
RETURN (!lTimeOut)
------------------------------------------------------------------------
In the statechanged method for the inet control, i added the codes:
*** ActiveX Control Event ***
LPARAMETERS state
* Retrieve server response using the GetChunk
* method when State = 12. This example assumes the
* data is text.
strData = ""
DO CASE
Case state == icNone
Case state == icHostResolvingHost && The control is looking up the IP address of the specified host computer.
Thisform.writelnlog("icHostResolvingHost")
Case state == icHostResolved && The control successfully found the IP address of the specified host computer.
Thisform.writelnlog("icHostResolved")
Case state == icConnecting && The control is connecting to the host computer.
Thisform.writelnlog("icConnecting")
Case state == icConnected && The control successfully connected to the host computer.
Thisform.writelnlog("icConnected")
Case state == icRequesting && The control is sending a request to the host computer.
Thisform.writelnlog("icRequesting")
strData = "icRequesting" + CHR(13) + CHR(10)
Case state == icRequestSent && The control successfully sent the request.
Thisform.writelnlog("icRequestSent")
Case state == icReceivingResponse && The control is receiving a response from the host computer.
Thisform.writelnlog("icReceivingResponse")
Case state == icResponseReceived && The control successfully received a response from the host computer.
Thisform.writelnlog("icResponseReceived")
Case state == icDisconnecting && The control is disconnecting from the host computer.
Thisform.writelnlog("icDisconnecting")
Case state == icDisconnected && The control successfully disconnected from the host computer.
Thisform.writelnlog("icDisconnected")
Case state == icError && An error occurred in communicating with the host computer.
Thisform.writelnlog("icError (" + TRANSFORM(This.ResponseCode) + ") : " + This.ResponseInfo)
Case state == icResponseCompleted && The request has completed and all data has been received.
Thisform.writelnlog("icResponseCompleted")
vtData = ""
bDone = .F.
Thisform.writelnlog("Retrieving Data...")
* Get first chunk.
cGetChunk = 0
vtData = This.GetChunk(1024, cGetChunk) && 0 - String, 1 - ByteArray
* DoEvents
Do While !bDone
strData = strData + vtData
DoEvents
* Get next chunk.
vtData = This.GetChunk(1024, cGetChunk)
If Len(vtData) == 0
bDone = .T.
EndIf
ENDDO
Thisform.writelnlog("Retrieving Completed...")
Thisform.writelnlog(strData,"O")
Thisform.txtDone.Value = .T.
Thisform.Refresh
EndCASE
------------------------------------------------------------------------
BTW, I tried WS_FTP lite and it has no problem with the same file. my test program works for smaller files (< 10kb)
Please advice
Cheers,
Peter
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement