Nathan Pralle - www.nathanpralle.com
Kickass Phone Rates from 3U
PLACES TO GO:  
Back to Software Print Version
Sybase PowerBuilder and FTP
Using WeOnlyDo! Software's FtpDLX Component in PowerBuilder
Scripts.com Freshmeat The Perl Archive HotScripts

Review of the Product:

I recently had the need to have FTP support in a PowerBuilder application I was writing for my day job. Since PowerBuilder does not natively support any sort of socket connections and the like (a big minus, Sybase), I knew that I had to find a suitable 3rd party product to perform the necessary operations, or attempt the wrath of the WinAPI directly, something I wasn't looking forward to doing.

Along came WeOnlyDo! Software's FtpDLX component that I found after a bit of searching on Google. They offer a free trial download that works for 30 days and I gave it a shot. At first, I had some problems understanding the process with which it worked under PowerBuilder but eventually I got the 'hang' of it and through several emails with WeOnlyDo! (WOD) support, I was able to easily make a working and powerful FTP product.

The WOD FtpDLX component is a combination COM and ActiveX component and can be installed and used in either manner, although my experience shows that it is only really possible to use it in the ActiveX state under PowerBuilder, due to the events-handling system. The component handles regular FTP, FTP+SSL, and SFTP connections with ease with multiple encryption protocols: DES, Triple DES, AES, Blowfish, DH, ADH, RC2, RC4, and IDEA. The functions are clear and defined; the events are handy and useful. In the ActiveX state, it provides a GUI user interface that you can use or not use at your leisure. I tended to not use it, as I wanted to control the user's experience more, but it would be easy to implement.

The component only costs $219 for a developer's license, and that's the last cost you'll have...ever. That's because along with a really good price, all updates and upgrades are free for the life of the product. Also, support is completely free. And the product is completely, 100% royalty-free. Did I mention that there's a lot of free stuff with this?

Support for the product through email is excellent. I have only ever emailed with one person, Kreso, and he has been phenomenal. The first time I emailed and said, "The product is great, but...it doesn't work," he simply emailed back and said, "It has to work...it's imperative. We'll make it work." He never blamed me for it not working, never said it couldn't do something, he just said, "It has to work." I like that in a product. A few emails later and we had solved the problem. It was my problem in the long run (I had read the docs wrong) but he was just as kind and helpful and never criticized once.

The documentation for the component is also very good. The help file comes in both PDF and Microsoft HTML Help (CHM) format for your ease of use and printing. The manual and help is very comprehensive, covering every aspect of the component. The help is clearly written for programmers as each method, event, and property is laid out in clear terms as to its parameters, return values, and actions (where appropriate). The only thing I found lacking was sample files and examples in PowerBuilder; there were examples written in VC and VB included.

All in all, if you're looking for an easy way to incorporate FTP into PowerBuilder (or any other language), this is an excellent product that is well worth the price for what you receive.
Using the Component in PowerBuilder

Since the FtpDLX component does not come with PowerBuilder examples and samples, I decided to chronicle here how to set it up and use it under PowerBuilder for any developers out there that might be interested. I developed these instructions using PowerBuilder 9.0.1 Build 7171 on Windows 2000 SP4, but I suspect these will work for just about any version of PowerBuilder from 7 on due to similarities.

Disclaimer: These are my experiences, your mileage may vary. I am not the official support for this product, but you may contact me if you have questions and I will try to answer them. Use of the instructions, recommendations, and advice contained herein and in any communication with me in any way whatsoever is at your own risk. I am not responsible for any damage to person or property that the use of these instructions might cause. These instructions come AS IS and have NO WARRANTY associated with them in any way. Now that I've covered my legal butt, off to the good stuff.

Prerequisites: This tutorial assumes decent knowledge of PowerBuilder, PowerScript, and associated functions. It assumes you either have the full or demo version of FtpDLX installed on your computer correctly and the ActiveX object is available to PowerBuilder. It also assumes you have a network connection to a local or remote FTP server running FTP, FTP+SSL, or SFTP protocols.

When using FtpDLX within PowerBuilder, you must use the ActiveX component and not the COM object. This is due to how PowerBuilder uses events from OLE; it can't process events from COM objects except through a default interface. However, when you insert an ActiveX object onto a window, PowerBuilder incorporates the object's events into the event listing for the OLE object, making it very simple to use.
  1. Create a window...any sort will do fine.
  2. Choose an OLE object from the object tool or choose Insert->Control->OLE...
  3. When the Insert Object window opens, choose the Insert Control tab.
  4. Scroll to the bottom and find the wodFtpDLX Class control. Select it, choose OK to close the window.
  5. Click on the window where you want to place the component. Move it around as you like. Name it to something useful (ole_wodftp is my name of choice)
  6. Now, you need to choose whether or not you want to use the visual part of this component. If you want to use the visual part of this control, then make the OLE object nice and large and put it somewhere significant on your screen. If you don't want to use the visual, make it small and tuck it away in some corner of the window -- we'll make it invisible later, but for now, leave it visible, it makes it easier to access the functions, events, and properties if you have something to click on.
  7. To refer to the object properties and methods, you'll have to use the full object dot syntax, as in: ole_wodftp.object.Property=Setting or for a method, ole_wodftp.object.Method(arg1,arg2).
  8. Now you're ready to set up some properties, invoke a few functions, and handle a few events. How you do all this is almost completely up to you -- You can have buttons on the screen for the user to click to invoke various things, you can do it all automatically, whatever. I'll show you how to set properties and such, the rest is up to you. The documents describe pre-defined enumerated constants for various settings, but these are not (as far as I can make out) available to you inside PowerBuilder. Therefore, you will have to refer to the settings by their raw value (usually an int).
  9. First, you have to set up some standard properties before you connect to the server:
    • ole_wodftp.object.Hostname - A string for the hostname of your FTP server.
    • ole_wodftp.object.Login - The login name
    • ole_wodftp.object.Password - The password
    • ole_wodftp.object.Authentication - 0 for both types, 1 for password authentication, 2 for certificate authentication
    • ole_wodftp.object.TransferMode - 0 for binary, 1 for ASCII
    • ole_wodftp.object.Blocking - TRUE to block, FALSE for non-blocking. I highly recommend FALSE as it's darn near impossible to do anything if you can't make this event-based.
    • ole_wodftp.object.protocol - Which protocol to use. 0 for regular FTP, 1 for SFTP, and 2 through 4 for various forms of FTP+SSL. Read the documents for more information.
    • ole_wodftp.object.Compression - How much compression to use in SFTP connections, if applicable. 6 is the preferred number, but you can have a range of 1 to 9.
    • ole_wodftp.object.Passive - Passive or active connection. 1 for passive, 0 for active.
  10. Now you're ready to connect to the server. A simple: ole_wodftp.object.Connect() will do the trick. Now, because this is event-based programming, the function will return immediately, even if it's not connected. You'll have to script something in either the "done" or "connected" events of the OLE object or set up a timer to read the "state" property to determine when it's done.
  11. To access the events, you should be able to just select the OLE object and go to the Events window and pull down a list of all available events. Script away! Helpful events to script include the following:
    • connected - Fires when a Connect() method is done connecting to the server.
    • disconnected - Fires when a Disconnect() method is done disconnecting from the server.
    • done - Fires every time some method is completed. Watch this one, if you script it and it does something extensive, you'll have it firing a lot...as in, after every single file of a multiple file transfer is completed.
    • looperror - When making multiple file transfers or looping through something, this fires if an error occurs.
    • loopitem - When making loops or multiple file transfers, this fires and lets you know what it happening on each item of the loop.
    • progress - Shows you how progress is being made on the file transfer. Useful for setting up HorizontalProgressBars.
  12. Sending Files: There are two ways to send files, you can either send them one at a time or with wildcards using PutFile(string localpath, string remotepath) or multiple files and directories recursively with PutFiles(string localpath (no wildcards allowed),string remotepath,int max_levels_recursion). PutFiles is by far the more powerful of the two but it depends on your application. As noted above, PutFile (singular) allows wildcards; PutFiles (plural) does NOT. This is an important distinction, as you might guess that PutFiles("e:\*.*","/",0) would send all files from E: to the server. Instead, it will hang without error. Don't mess those up. The correct format would be: PutFiles("e:\","/",0). The zero means "no limit" to the recursiveness. (watch how deep you let it go!)
  13. Getting Files: Getting files is very similar to sending files. GetFile(string localpath,string remotepath) is the function to get one file or multiples using wildcards; GetFiles(string localpath,string remotepath,int max_level_recusion) is the method to use to grab files and directories recursively. As with the Sending methods, GetFile allows wildcards; GetFiles does NOT. Read above for more information.
  14. Disconnecting: Disconnecting is as simple as issuing the Disconnect() method as such: ole_wodftp.object.Disconnect(BOOLEAN) where BOOLEAN is TRUE to make it log out of the server correctly; FALSE drops the connection without another word.
That is the basic idea behind the component. There are a multitude of options and other methods to be run and events to catch, but I only have so many electrons and once you get the idea, you can expand as necessary. Again, this is my experience with the component but it has been extremely friendly; if you have questions or commentary, you can contact me and I'll do the best to answer you. Questions for WeOnlyDo! Software should be directed to general@weonlydo.com. You can access their products and information at www.weonlydo.com.
PowerBuilder Code
This code is provided for example purposes only and is provided without any warranty.

Setup and Connect to the Server:
ole_wodftp.object.Hostname="your.host.com"
ole_wodftp.object.Login="your_login"
ole_wodftp.object.Password="your_password"
ole_wodftp.object.Authentication=1 //password auth
ole_wodftp.object.TransferMode=0 //binary mode
ole_wodftp.object.Blocking=FALSE //don't block, we're using events
ole_wodftp.object.protocol=1 //use SFTP
ole_wodftp.object.Compression=6 //compression factor
ole_wodftp.object.Passive=1 //passive mode (shouldn't matter with SFTP)
ole_wodftp.object.Connect()

Put a directory of files to the server:
ole_wodftp.object.PutFiles("e:\pages",ole_wodftp.object.RemotePath,0)

Scripting for the Progress() event:
hpb_progress.maxposition=total
hpb_progress.position=position

Disconnect from the server:
ole_wodftp.object.Disconnect(TRUE)


This site and all content (C)2002-2008 Nathan E. Pralle (www.nathanpralle.com).