Sie sind auf Seite 1von 10

Second life for Clipper Application by Aleksandar Stefanovic

One
ALASKA XBASE++
ACTIVEX
EXAMPLE
Using SEEKFORD SOLUTIONS
FTP ACTIVEX (one component from IP
Wizard Toolpack 3.0)

1
Second life for Clipper Application by Aleksandar Stefanovic

Application (or you as programmer) need FTP functions (sometimes). I hope you know
what I am talking about. Alaska Xbase++ v.1.9.331 support COM/ActiveX objects but I
must say that when you want to use any of them , please, check it because limited number
of variable types sometimes can make problems.
Don’t be afraid, you will find ActiveX controls that work great with ALASKA XBASE.
One of them is FTP ActiveX control from SEEKFORD SOLUTIONS. Here we will give
you listing of one XBASE function that will help you if you want FTP download or
upload ability. You can use it as is or make any changes that you need.

This is listing of SEEKFTP.PRG

Here you will find SEEKFTP function with 6 parameters.


Server – FTP server
User - user ID
Password – Password
sWhere – directory on ftp server
sFile – file name
nWhat – what we want to do, download (0) or upload (1)

#include "Gra.ch"
#include "Xbp.ch"
#include "Appevent.ch"
#include "Font.ch"
#include "dll.ch"
#include "nls.ch"
#include "inkey.ch"
#PRAGMA LIBRARY( "ASCOM10.LIB" )

func seekftp(server,user,password,sWhere,sFile,nWhat)
LOCAL nEvent, mp1, mp2,drawingArea, aEditControls := {}
public oDlg
public oXbp
public oXbpserver
public oXbpdatoteka
public oXbpsta
public oXbpporuka
public oXbptok
public oKom:=0
public ssta:=nWhat

SET TIME TO HH:MM:SS

2
Second life for Clipper Application by Aleksandar Stefanovic

oDlg := XbpDialog():new( AppDesktop(), , {100,100}, {200,330}, , .F.)


oDlg:taskList := .T.
oDlg:title := "AS FTP Transfer"
oDlg:sysmenu:=.f.
oDlg:create()

drawingArea := oDlg:drawingArea
drawingArea:setFontCompoundName( "8.Arial" )

oXbpserver:= XbpStatic():new( drawingArea, , {12,150}, {150,24}, { {


XBP_PP_COMPOUNDNAME, "16.Times New Roman" } } )
oXbpserver:caption := server
oXbpserver:clipSiblings := .T.
oXbpserver:options := XBPSTATIC_TEXT_BOTTOM
oXbpserver:create()

oXbpdatoteka := XbpStatic():new( drawingArea, , {12,200}, {150,24}, { {


XBP_PP_COMPOUNDNAME, "16.Times New Roman" } } )
oXbpdatoteka:caption := sfile
oXbpdatoteka:clipSiblings := .T.
oXbpdatoteka:options := XBPSTATIC_TEXT_BOTTOM
oXbpdatoteka:create()

oXbpsta := XbpStatic():new( drawingArea, , {12,250}, {150,24}, { {


XBP_PP_COMPOUNDNAME, "16.Times New Roman" } } )
if sta==0
oXbpsta:caption := "receive file"
else
oXbpsta:caption :="send file"
endif

oXbpsta:clipSiblings := .T.
oXbpsta:options := XBPSTATIC_TEXT_BOTTOM
oXbpsta:create()

oXbpporuka := XbpStatic():new( drawingArea, , {12,48}, {150,24}, { {


XBP_PP_COMPOUNDNAME, "16.Times New Roman" } } )
oXbpporuka:caption := ""
oXbpporuka:clipSiblings := .T.
oXbpporuka:options := XBPSTATIC_TEXT_BOTTOM
oXbpporuka:create()

3
Second life for Clipper Application by Aleksandar Stefanovic

oXbptok := XbpStatic():new( drawingArea, , {12,72}, {156,24}, { {


XBP_PP_COMPOUNDNAME, "16.Times New Roman" } } )
oXbptok:caption := "Way"
oXbptok:clipSiblings := .T.
oXbptok:options := XBPSTATIC_TEXT_BOTTOM
oXbptok:create()

oXbp := XbpPushButton():new( drawingArea, , {24,12}, {120,24}, { {


XBP_PP_BGCLR, XBPSYSCLR_BUTTONMIDDLE }, { XBP_PP_FGCLR, -58 } } )
oXbp:caption := "Beak "
oXbp:tabStop := .T.
oXbp:create()
oXbp:activate := {|| nEvent:=xbeP_Close }

oDlg:show()

////////////////////////////////////////////////////////

// We create SEEKFORD ACTIVEX


oKom := ActiveXObject():create("FTPWIZARD.FTPWizardCtrl3")

if oKom<>NIL
oXbpporuka:setcaption("Control Created OK" )
else
msgbox("FTP control unavailable")
oDlg:destroy()
return (NIL)
endif
// Unlock control (when you buy it you will get unlock code)
oKom:UnlockFTPWizard("xxxxxxxxxxxxxxxxxx")
// We will define our block for events
tEvents()
oKom:Asynchronous:=.f.
oKom:UsePassiveFTP:=.f.
oXbpporuka:setcaption("Internet ???")
if oKom:OpenInternetConnection(1,"")
oXbpporuka:setcaption("Internet OK!")
else
msgbox("There is no internet access")
oDlg:destroy()
return (NIL)
endif

4
Second life for Clipper Application by Aleksandar Stefanovic

oXbpporuka:setcaption("FTP server ???")


if oKom:OpenFTPConnection(server,user,password)
oXbpporuka:setcaption("FTP OK")
else
msgbox("FTP site unavailable")
oKom:CloseInternetConnection()
oKom:destroy()
oDlg:destroy()
return (NIL)
endif

if gde<>"\"
oKom:SetCurrentDirectory(gde)
endif
if sta==0

oKom:SetFileDownloadMethod(.t.)
oKom:Asynchronous:=.t.

oKom:GetFTPFileWithControl(sFile,sFile,.t.)
else
oKom:Asynchronous:=.t.

oKom:UploadFTPFileWithControl(sFile,sFile,.t.)
endif

nEvent := xbe_None

DO WHILE nEvent <> xbeP_Close

nEvent:=AppEvent(@mp1,@mp2,@eXbp,20)
if eXbp<>NIL
eXbp:handleevent(nEvent, mp1,mp2)
else

endif
enddo
oKom:Asynchronous:=.f.
oKom:CloseFTPConnection()
oKom:CloseInternetConnection()
oKom:destroy()
oDlg:destroy()
RETURN (NIL)

5
Second life for Clipper Application by Aleksandar Stefanovic

function tEvents()
SFileTransferStatus()
SOnCommandCompleted()
SOnConnect()
SOnDisconnect()
SOnError()
RETURN (NIL)

function SFileTransferStatus()
oKom:FileTransferStatus:={|s1,s2,n1,n2|myftstatus(s1,s2,n1,n2)}
return (NIL)

function myftstatus(s1,s2,n1,n2)

oXbptok:setcaption(str(n1,10))
return (NIL)

function SOnCommandCompleted()
oKom:OnCommandCompleted:={|n1,n2,n3|myOnCommandCompleted(n1,n2,n3)}
return(NIL)

function myOnCommandCompleted(n1,n2,n3)
oXbpTok:setcaption("Transfer completed")
return (NIL)

function SOnConnect()
oKom:OnConnect:={||MyOnConnect()}
return (NIL)

function myOnConnect()
oXbptok:setcaption("Connection ON")
return (NIL)

function SOnDisconnect()
oKom:OnDisconnect:={||myOnDisconnect()}
return (NIL)

function myOnDisconnect()
oXbptok:setcaption("Break")
//imakonekcija:=0
return (NIL)

function SOnError()
oKom:OnError:={|n,s|myOnError(n,s)}
return(NIL)

6
Second life for Clipper Application by Aleksandar Stefanovic

func myOnError(n,s)
msgbox("error:"+str(n)+" "+s)
return (NIL)

You can use this listing as is but better thing is to understand how we use ActiveX
object.

Let’s go from the start.

#PRAGMA LIBRARY( "ASCOM10.LIB" )

This is library that we need to access activex objects. YOU MUST USE IT EVRY TIME
WHEN YOU WANT TO USE ACTIVEX CONTROLS.

oKom := ActiveXObject():create("FTPWIZARD.FTPWizardCtrl3")

You need ActiveX control to be installed on your PC. Upper row show you how to
incorporate control in your application.

Please remember that sometimes you will need to add some license information in
activex creating step. This control don’t have this kind of protection, they use another
method, so you must get serial number from them and send it to unlock function like this

oKom:UnlockFTPWizard("xxxxxxxxxxxxxxxxxx")

For setting other properties and events functions just read users guide. You will not have
problems that can be found in some activex controls when we have the same name for
property and for event. If you have problems like this you must get ID like numbers to
acces them. With this control this is not a case.

When we get oKom as ActiveX ID we can access properties:

Asynchronous
UsePassiveFTP
VersionInfo

Like this

7
Second life for Clipper Application by Aleksandar Stefanovic

oKom:Asyncronous
oKom:UsePassiveFTP
oKom:VersionInfo

VersionInfo is READ ONLY but other properties you can change.

EXAMPLE

oKom:Asyncronous:=.f. // we use blocking mode


oKom:UsePassiveFTP:=.f. // we don’t want passive mode

sVersion:=oKom:Version //we want version string

Method that we can find are:

UploadMemoryFile
DownloadFileToMemory
AboutBox
AbortCotrolledTransfer
CloseFTPConnection
CloseInternetConnection
CreateDirectory
DeleteFile
GetCurrentDirectory
DoEvents
GetCurrentDirectoryAsURL
GetEntriesFromCurrentDirectory
GetFTPFileWithControl
GetFTPFileWithoutStatus
GetLastErrorCode
GetLastErrorDescriptin
OpenFTPConnection
OpenInternetConnection
RemoveDirectory
SetCurrentDirectory
SetFileDownloadMethod
UnlockFTPWizard
UploadFTPFileWithControl
UploadFTPFileWithoutStatus
Rename File

Accessing is easy just add oKom: before method (like oKom:OpenInternetConnection()


where oKom is varuable with ID value for ActiveX control)

8
Second life for Clipper Application by Aleksandar Stefanovic

Events are:

FileTransferStatus
OnCommandCompleted
OnConnect
OnDisconect
OnError

If any events is interesting for you add code block like in this example

oKom:OnError:={|n,s|myOnError(n,s)}

func myOnError(n,s)
msgbox("error:"+str(n)+" "+s)
return (NIL)

In this control you can find two more classes FileInfo and FieInfos. Use them when you
need directory information.

We know that price for this control is not the best one but sometimes you can get IP
Wizard ToolPack for only $49, They call it crazy sell. When they do that? Once or two
times per year. With this price this is the best choice in town.

Check it from time to time

You can get all of the following controls:

• POP3 Wizard SSL allows you to receive mail from any POP3 server. It even has
a special Message object which allows you to interpret the message, read the
headers, and even save attached files. Also lets you easily get the HTML or
Plaintext body of a message. You are also able to communicate using SSL so that
hackers can't read your messages.
• SMTP Wizard SSL gives you control over sending messages. With the special
SMTPMessage object, you can modify headers, set the message body, and even
attach files. It now has the easy capability of sending HTML messages as well as
the traditional plain-text messages. You are also able to communicate using SSL
so that hackers can't read your messages.
• Encoder Wizard allows you to encode and decode text from and to Base64,
Quoted-Printable, UUEncode, yEnc, URL, SHA-1, MD-5, and Binary 2 Hex. You
can use this to encode your own custom messages and have it in a proper format

9
Second life for Clipper Application by Aleksandar Stefanovic

for transmission through email gateways. Except for the digest algorithms(which
are one-way), Encoder wizard can also decode all the data back to its original
form.
• MIME Wizard allows you to create and parse MIME messages with an easy to
use object model. Using the standards for MultiPart Internet Messages you can
build simple or complex messages.
• HTTP Wizard SSL provides simple and easy downloading of web pages and
files, uploading of files to servers, posting Form data, authentication, redirection,
cookies and much more. .
• FTP Wizard lets you upload and download files using the file transfer protocol.
You also are able to get directory entries in an easy to use object oriented format.
All basic commands are supported. You can rename, create directories, delete
files and directories.
• NNTP Wizard allows you easily use every command that is supported by the
Network News Transport Protocol. Post articles, download articles, groups, and
headers. With support for all the commands you can also use the XHDR
commands and NEWNEWS, etc. Comes with an Article object which grabs
attachments for you.
• Ping Wizard lets you ping servers to get the Return Trip Time(RTT) as well as
the Time to Live(TTL). Great for detecting network uptime and presence. Also
works for checking to see if the local computer has an internet connection that is
active.
• TraceRoute Wizard allows you to evaluate the time it takes for a packet to reach
its intended host. Detect network congestion, overloaded or inefficient routers,
and more.
• Finger Wizard lets you query Finger servers to find information about their
users. Some servers use the Finger query for earthquake and geological data
retrieval. Most servers use the protocol to release data about email accounts and
user accounts on the server..
• WHOIS Wizard lets you pull up the WHOIS information record on domain
names. Discover who owns a domain name and their contact information..
• SNTP Wizard allows your program to synchronize with Atomic clocks and radio
frequency clocks across the internet for highly precise timestamping. You can
also set the local computers clock to the correct time with a simple command.
SNTP Wizard automatically provides conversions from Universal Coordinated
Time(UTC) to the local computers timezone. That way you can use either value
for your timestamp..
• DNS MX Wizard lets you access the Mail Exchange(MX) Resource
Records(RR) from a DNS server.
• SSL Socket Wizard allows you to connect to ports on a server(computer or
device) using TCP and communicate using plain-text(normal) or use SSL(secure
channel) for sending and receiving data.

I believe that you will agree with me that using ActiveX components is very easy with
ALASKA XBASE++.

10

Das könnte Ihnen auch gefallen