Reliable FTP communication using an OCX

Is there an OCX which offers the possiblity of sending a file via FTP and returning an error if the file Transfer has not been successfull (ie: The FTP site at the other end is down or the connection has timed out) I’m aware that Cute-FTP is packaged with an OCX but I was wondering if it returns an error when the file transfer has failed ? - Has anyone developed a reliable file Transfer Module in Navision using a FTP ocx ? ____________________ Happy New Year 2003 ____________________

I’m using the OCX from Cute-FTP. Until now i have no special errorhandling. But the following Help-Page from Cute-FTP may help you: Error Handling You can capture and deal with errors differently in the various programming and scripting languages. An example for dealing with errors in Visual Basic Scripting, and one using a Transfer Engine property are provided below. You can use these for capturing an error message after a certain command fails and then handle the error appropriately. Note Each method may return an error during execution. In order to catch such errors you should use “On Error” VB statements. There are 2 types of this statement in VB script. Visual Basic Syntax On Error Resume Next On Error GoTo 0 Visual Basic Example Set MySite = CreateObject(“CuteFTPPro.TEConnection”) 'setup various properties here MySite.Host = “bad.host.name” On Error Resume Next MySite.Connect Err.Raise 6 ’ Raise an overflow error. MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description Err.Clear ’ Clear the error. Transfer Engine Error Handling Example Set MySite = CreateObject(“CuteFTPPro.TEConnection”) 'setup various properties here MySite.Host = “bad.host.name” MySite.Option(“ThrowError”) = false if not CBool(MySite.Connect) then MsgBox "Error : " & MySite.ErrorDescription end if

On Error Resume Next On Error GoTo 0 are VB niceties [:D] Navision do not offer anything similar as yet. The imlementation of my FTP module has got to be written in Navision (CAL code calling an OCX) Some FTP programs are able out output an error log every day, I could easily write a dataport to process the data but I was looking for a more elegant approach (“Everything is relative” some would say [;)]) Basically what I’m looking for is an OCX that allows me to know if the file transfer has been successful or not : OK → Boolean FTPOCXvariable → The unfamous FTP OCX OK := FTPOCXvariable.TransferStatus; Does anyone know an OCX which enables to do something similar ?

hi tarek, ok, the example is in VB but you can do the same in Navision. Code-Example in Navision with Cute-FTP OCX without errorhandling: CREATE(FTP); FTP.Host := LVSLagerort.“FTP Host”; FTP.Login := LVSLagerort.“FTP User”; FTP.Password := LVSLagerort.“FTP Passwort”; FTP.Connect; FTP.RemoteFolder := LVSLagerort.“FTP Transferordner”; FTP.LocalFolder := LVSLagerort.“Arbeitsordner Ausgang”; FTP.Upload(iDatei); FTP.RemoteRename(RenameFrom,RenameTo); FTP.Disconnect; CLEAR(FTP); The Methods like CONNECT and UPLOAD can return an error. To handle these errors you need (for Navision) the last part of the help page. In my example it could be (not tested): FTP.Option(“ThrowError”) = false if not FTP.Connect then MESSAGE(‘Error : %1’,FTP.ErrorDescription //or handle the error something else end if Description for “ThrowError”: If set to False, then if some transfer method fails the script will continue to the next command (-> means “on error resume next” [:)]) Cute-FTP Pro has a good online-help with a lot of code-examples. I think with this ocx you cann all the things do, you want. The OCX has also a Log-Function: Writing messages in a log Description Use the WriteToLOG method to write a messaged directly to the connection log saved in the path set in CuteFTP Pro’s global options. It is useful for documenting events to aid in script debugging. Syntax Object.WriteToLOG(BSTR bstr , BSTR bstrType) Parameters bstr The log message. bstrType A log message, type: “STATUS”, “ERROR”, “NOTE”, “COMMAND”, “RAW”. The default is “STATUS”. Example Set MySite = CreateObject(“CuteFTPPro.TEConnection”) ‘Initialize all necessary fields for MySite : host name, user, password, etc. MySite.TransferURLAsync “ftp://ftp.cuteftp.com/pub/cuteftp” strResult = MySite.Wait If (strResult = “FINISHED”) then MySite.WriteToLOG “Transfer successful!!”, “note” End if And hey, about the “on error” in VB you can think what ever you want, but it would be very useful in Navision [;)]

Tarek… another way is creating a new ocx for controlling the one you’re wanting to use like CuteFTPPro’s one and returning navision the errors, so navision will just use your new nongraphical ocx, that will call the functions in CuteFTPPro’s OCX and handle/return the appropiate messages to navision.

Is it possible to do some “decent” error handling regarding the connection, let’s say your FTP site is down (you can simulate it be setting a non-existant FTP address) Could you do something like that with the Cute FTP component : ConnectionStatus := 0; Retry := 0; MaxRetry := 10; WHILE (ConnectionStatus <> -1) AND (Retry <> MaxRetry) DO BEGIN ConnectionStatus := CuteFTP.Connect; Retry := Retry + 1; END; If MaxRetry = Retry THEN FTPServerNotAnswering := TRUE;

quote:


Originally posted by Uwe
hi tarek, ok, the example is in VB but you can do the same in Navision. Code-Example in Navision with Cute-FTP OCX without errorhandling: CREATE(FTP); FTP.Host := LVSLagerort.“FTP Host”; FTP.Login := LVSLagerort.“FTP User”; FTP.Password := LVSLagerort.“FTP Passwort”; FTP.Connect; FTP.RemoteFolder := LVSLagerort.“FTP Transferordner”; FTP.LocalFolder := LVSLagerort.“Arbeitsordner Ausgang”; FTP.Upload(iDatei); FTP.RemoteRename(RenameFrom,RenameTo); FTP.Disconnect; CLEAR(FTP); The Methods like CONNECT and UPLOAD can return an error. To handle these errors you need (for Navision) the last part of the help page. In my example it could be (not tested): FTP.Option(“ThrowError”) = false if not FTP.Connect then MESSAGE(‘Error : %1’,FTP.ErrorDescription //or handle the error something else end if Description for “ThrowError”: If set to False, then if some transfer method fails the script will continue to the next command (-> means “on error resume next” [:)]) Cute-FTP Pro has a good online-help with a lot of code-examples. I think with this ocx you cann all the things do, you want. The OCX has also a Log-Function: Writing messages in a log Description Use the WriteToLOG method to write a messaged directly to the connection log saved in the path set in CuteFTP Pro’s global options. It is useful for documenting events to aid in script debugging. Syntax Object.WriteToLOG(BSTR bstr , BSTR bstrType) Parameters bstr The log message. bstrType A log message, type: “STATUS”, “ERROR”, “NOTE”, “COMMAND”, “RAW”. The default is “STATUS”. Example Set MySite = CreateObject(“CuteFTPPro.TEConnection”) ‘Initialize all necessary fields for MySite : host name, user, password, etc. MySite.TransferURLAsync “ftp://ftp.cuteftp.com/pub/cuteftp” strResult = MySite.Wait If (strResult = “FINISHED”) then MySite.WriteToLOG “Transfer successful!!”, “note” End if And hey, about the “on error” in VB you can think what ever you want, but it would be very useful in Navision [;)]


quote:


Originally posted by Tarek Demiati
Is it possible to do some “decent” error handling regarding the connection, let’s say your FTP site is down (you can simulate it be setting a non-existant FTP address) Could you do something like that with the Cute FTP component : ConnectionStatus := 0; Retry := 0; MaxRetry := 10; WHILE (ConnectionStatus <> -1) AND (Retry <> MaxRetry) DO BEGIN ConnectionStatus := CuteFTP.Connect; Retry := Retry + 1; END; If MaxRetry = Retry THEN FTPServerNotAnswering := TRUE;


Hi Tarek, here is one solution which i tested and it works fine: LVSLagerort.GET(‘19’); CREATE(FTP); FTP.Host := LVSLagerort.“FTP Host”; FTP.Login := LVSLagerort.“FTP User”; FTP.Password := LVSLagerort.“FTP Passwort”; FTP.Retries := 3; FTP.Delay := 10; //wait 10 seconds between retries FTP.Option(‘ThrowError’,0); //0=FALSE FTP.Connect; IF FTP.IsConnected <> -1 THEN MESSAGE('Error: ’ + FTP.ErrorDescription) ELSE MESSAGE(‘Connected’); FTP.Disconnect; CLEAR(FTP); The error message in this case for example is: Error: Can’t resolve “<host=?}”. because LVSLagerort.“FTP Host” has no value.

Other question : How can you get the list of files for a given remote FTP site (after setting the RemoteFolder property) I need to populate a Navision table with the files details which are on the FTP directory

I have just found the syntax : CuteFTP.GetList(’/testcute’, ‘C:\CuteDirectoryData.txt’, ‘NAME= %NAME SIZE= %SIZE DATE= %DATE’); This creates a file on my C drive that contains all the files names which are on the FTP server so I will just need to import it using a Dataport. It works really nicely …

I’m now experiencing a new error when I’m using the Cute FTP Pro 3.0 Client : ERROR:> Can’t connect to remote server. Socket error = #10060. 425 Can’t open data connection. The funny thing is that it does not TIME OUT when I use Internet Explorer (with the same FTP parameter) and display the different folders quite quickly, has anyone experienced this problem before ?

Are you using passive mode??? Check with the own cuteftp connecting to that ftp and check if it’s working fine when both connecting in passive mode and not in passive mode. Regards,

That was actually the problem, it was set at the client side in PASSIVE mode so I switched to PORT on the client side and it worked fine. I experienced the same problem in my code so I forced it like that CuteFTP.DataChannel := ‘PORT’ Apparently some FTP Server prefers PORT for data connections rather than PASV (Passive Mode)

quote:


Originally posted by apertierra
Are you using passive mode??? Check with the own cuteftp connecting to that ftp and check if it’s working fine when both connecting in passive mode and not in passive mode. Regards,


We’ve manage to write a neat communication package for uploading and downloading files automatically to our subsidiaries. The package has been performing extremly well, beside an error message which sometimes occurs randomly with not really a logical pattern. The Error message is the following : “This message is for CA/L programmers Could not invoke the member Connect. The OLE control or Automation server return an unknown code.” I’m 100% sure that I’ve created an instance of the CuteFTP Automation before calling the Connect Method, So I really don’t have a clue on what’s the trick for not getting this error message. This error message occurs very rarely, during our testing period we manage to upload 5000 and download 5000 files without getting this error.