Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Sapphire Soltuions

eVB and FTP using John Clavey's custom SapphireRAS DLL

Written by Derek Mitchell  [author's bio]  [read 33981 times]
Edited by Derek

Download the code

Page 1 

FTP connections within eVB or VB.NET

With the web being an extremely powerful tool in creating truly mobile applications, you can now incorporate the power of the File Transfer Protocol (FTP) right into your eVB or VB.NET applications. Sapphire Solutions Ltd have developed an easy-to-use utility that can connect to a remote FTP server, search for directory listings, upload and download files or directories and create, rename and delete items.

Overview

You can download the demo project of the Sapphire FTP DLL which includes a personal use version of the utility. This utility allows advanced FTP functionality such as:

  • Open and close a FTP session
  • Upload and download files
  • Remote directory navigation
  • Search for files and directories with attributes
  • Remove files and directories
  • Rename files and directories
  • Create directories
  • Upload and download directories (including contents)
  • Check if a remote file exists

Running the Project

After downloading and unzipping the SapphireFTP demo project, you need to add the appropriate version of the SapphireFTP.DLL to the \Windows directory on your Pocket PC. If you are using VB.NET, you will need to include the SapphireFTP.DLL into the application directory of your program instead. You can find the correct DLL in the unzipped project directory under the appropriate sub-directory. Once you have done this you can run the desired project file on the client device.

This demo project is a multi-purpose project that demonstrates the functionality of both the Sapphire FTP and Sapphire RAS utilities. Depending on which DLLs you have installed on your client device, the demo project will allow you to use the associated functionality.

In terms of the FTP functionality, when you enter the FTP explorer you will be able to connect to the remote server (specified under the FTP settings) and perform a variety of functions on both the local device and the remote server.

FTP Settings

The FTP Settings allow you to enter the remote server address, either a domain name or IP address. You can also specify the username and password for the FTP connection. If you require an anonymous connection, use 'Anonymous' as the username and your email address as the password.

The Code

To implement FTP functionality in your own eVB or VB.NET application you only need to create a few simple calls to the DLL.

Example: Linking the DLL using VB.NET

<DllImport("SapphireFTP.dll")> _
Public Function sFTPOpen( _
  ByVal sServer As String, _
  ByVal lPort As Integer, _
  ByVal sUser As String, _
  ByVal sPwd As String, _
  ByVal lPassive As Integer, _
  ByVal lTimeOut As Integer, _
  ByVal lLicence As Integer) As Integer
End Function


<DllImport("SapphireFTP.dll")> _
Public Function sFTPClose( _
  ByVal lLicense As Integer) As Integer
End Function

<DllImport("SapphireFTP.dll")> _
Public Function sFTPPull(_
  ByVal sRemoteFile As String, _
  ByVal sLocalFile As String, _
  ByVal bOverWriteFile As Byte, _
  ByVal lTransferType As Integer, _
  ByVal lLicence As Integer) As Integer
End Function

Example: Linking the DLL using eVB

Declare Function sFTPOpen _
  Lib "SapphireFTP.dll" ( _
  ByVal sServer As String, _
  ByVal lPort As Long, _
  ByVal sUser As String, _
  ByVal sPwd As String, _
  ByVal lPassive As Long, _
  ByVal lTimeOut As Long, _
  ByVal lLicence As Long) As Long

Declare Function
sFTPClose _
  Lib "SapphireFTP.dll" ( _
  ByVal lLicense As Long) As Long

Declare Function sFTPPush _
  Lib "SapphireFTP.dll" ( _
  ByVal sLocalFile As String, _
  ByVal sRemoteFile As String, _
  ByVal lTransferType As Long, _
  ByVal lLicence As Long) As Long

A simple example on how to create an FTP connection is shown below:

lResult = sFTPOpen(sFTPSession, lPort, _
  sFTPUsername,sFTPPassword, lPassive, lTimeOut, _
  SapphireFTPLicence)

  • lResult contains the number of any possible error that may have been encountered.
  • sFTPSession is the name of the remote FTP server.
  • lPort is the port number of the remote FTP server. By default this should be 21.
  • sFTPUsername is the username for the FTP account.
  • sFTPPassword is the password for the FTP account.
  • lPassive is a long specifying whether to use passive mode or not. 1 = Passive, 0 = Non-passive.
  • lTimeOut is the connection timeout in milliseconds.
  • SapphireFTPLicence is the licence number for registered users of the utility. For the demo project, this will be 1234567890.

Below is a simple example on how to download a remote file:

lResult = sFTPPull(sRemoteFile, sLocalFile, _
  FTP_OVERWRITE, FTP_TRANSFER_BINARY, _
  SapphireFTPLicence)

  • lResult contains the number of any possible error that may have been encountered.
  • sRemoteFile is the filename of the remote file.
  • sLocalFile is the name of the file to create when downloading the remote file.
  • FTP_OVERWRITE is a flag to state that the local file will be overwritten if it exists.
  • FTP_TRANSFER_BINARY is a flag to state the remote file is binary opposed to ASCII text.
  • SapphireFTPLicence is the licence number for registered users of the utility. For the demo project, this will be 1234567890.

Please refer to the demo project for a more complete example on how to use the utility including error capturing.

Where to find the demo

The product information page for the latest Sapphire FTP utility allows you to download the personal use version that includes the sample eVB and VB.NET projects with the demo version of the DLL for each target platform. This can be found at www.sapphire-solutions.co.uk/product.asp?product=FTP.

Licence of use

For those that wish to simply experiment with the utility or use it for personal projects, you can use the utility absolutely free of charge.

For those that wish to include the utility into their own commercial applications, they can purchase a royalty-free licence for the utility online at http://www.sapphire-solutions.co.uk. This is a one off payment that allows you to distribute it in any projects created under the registered company. Please refer to the web site for the latest prices.

Other utilities you may find useful

Sapphire Solutions Ltd have a variety of other utilities that you may find useful or vital to your application. Some of these are:

  • Sapphire RAS - Dial up a remote connection and manage phone book.
  • Sapphire GZip - Compress and decompress files into .gz or .zip format.
  • Sapphire Encrypt - Encrypt or decrypt strings or files ensuring its confidentiality.
  • Sapphire IrDA - Use your application to print on an IrDA enabled printer.
  • Sapphire Buttons - Take control of other buttons on your device.

Please check www.sapphire-solutions.co.uk for a full listing of available products.