LEADRasterFTP Sample for Visual Basic

Take the following steps to use FTP features, including Directory Browsing, to your application:

1.

Start Visual Basic.

2.

Add the LEAD Raster Object Library and LEAD Raster Variant Object Library to your project.

 

For VB5: On the Project pull-down menu, use the References option, and select the LEAD Raster Object Library (14.5).

 

For VB5: On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library (14.5).

3.

Add the LEAD RasterIO Object Library to your project.

 

For VB5: On the Project pull-down menu, use the References option, and select the LEAD RasterIO Object Library (14.5).

4.

Add the LEAD RasterFTP Object Library to your project.

 

For VB5: On the Project pull-down menu, use the References option, and select the LEAD RasterFTP Object Library (14.5).

5.

Add the following lines to the General Declarations section at the top of your form's code:

Dim WithEvents FTPObj As LEADRasterFTP
Dim RasterObj As LEADRaster
Dim IOObj As LEADRasterIO

6.

Add a command button to your form and name it as follows:

 

Name

Caption

 

FTP

Test FTP

7.

Add the following initialization code to the main form's Load procedure. In online help, you can use the Edit pull-down menu to copy the block of code.

Private Sub Form_Load()
   Set FTPObj = CreateObject("LEADRasterFTP.LEADRasterFTP")
   Set RasterObj = CreateObject("LEADRaster.LEADRaster")
   Set IOObj = CreateObject("LEADRasterIO.LEADRasterIO")
   FTPObj.EnableMethodErrors = False
End Sub

8.

Code the FTP button's click procedure as follows:

Private Sub FTP_Click()
   ' Connect to FTP server
   FTPObj.InetFtpConnect "10.1.1.113", 21, "anonymous", "password"
   ' Change working directory on the server
   FTPObj.InetFtpChangeDir "/pub/TestFolder"
   ' Check that the change took effect
   Me.Caption = "currently in: " + FTPObj.InetFtpGetCurrentDir
   ' Display the contents of the directory using the FTPBrowse event
   FTPObj.InetFtpBrowseDir "*.*"
   ' Send a file to the server
   FTPObj.InetFtpSendFile "c:\local.txt", "remote.txt", SENDAS_BINARY
   ' rename a file on the server
   FTPObj.InetFtpRenameFile "remote.txt", "remote2.txt"
   ' get a file from the server
   FTPObj.InetFtpGetFile "remote2.txt", "c:\local2.txt", True, SENDAS_BINARY
   ' create a new directory on the server
   FTPObj.InetFtpCreateDir "/pub/TestFolder/SubFolder"
   ' send a LEAD COM image to a file on the server
   IOObj.Load RasterObj, "v:\images\eagle.cmp", 0, 1, 1
   FTPObj.InetFtpSendBitmap RasterObj, FILE_BMP, 4, 0, "SubFolder/test.bmp", SENDAS_BINARY
   ' delete a file on the server
   FTPObj.InetFtpDeleteFile "SubFolder/test.bmp"
   ' remove a directory from the server
   FTPObj.InetFtpDeleteDir "SubFolder"
   ' end the connection with the server
   FTPObj.InetFtpDisconnect
End Sub

9.

Code the FTPBrowse event as follows:

Private Sub FTPObj_FtpBrowse(ByVal pszFile As String, ByVal FileAttrib As Long, ByVal CreateTime As Date, ByVal AccessTime As Date, ByVal LastWriteTime As Date, ByVal uFileSize As Long)
   Dim s As String

   FTPObj.StopFtpBrowseEvent = False
   s = "File name: " + pszFile + vbNewLine
   s = s + "File Attributies:" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_ARCHIVE) <> 0 Then s = s + vbTab + "Archive" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_COMPRESSED) <> 0 Then s = s + vbTab + "Compressed" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_DIRECTORY) <> 0 Then s = s + vbTab + "Directory" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_ENCRYPTED) <> 0 Then s = s + vbTab + "Encrypted" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_HIDDEN) <> 0 Then s = s + vbTab + "Hidden" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_NORMAL) <> 0 Then s = s + vbTab + "Normal" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_OFFLINE) <> 0 Then s = s + vbTab + "Offline" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_READONLY) <> 0 Then s = s + vbTab + "Readonly" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_REPARSE_POINT) <> 0 Then s = s + vbTab + "Reparse point" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_SPARSE_FILE) <> 0 Then s = s + vbTab + "Sparse file" + vbNewLine
   If (FileAttrib And FTP_FILE_ATTRIB_SYSTEM) <> 0 Then s = s + vbTab + "System" + vbNewLine

   If (FileAttrib And FTP_FILE_ATTRIB_TEMPORARY) <> 0 Then s = s + vbTab + "Temporary" + vbNewLine
   s = s + "Create Time:" + vbTab + Str(CreateTime) + vbNewLine
   s = s + "Access Time:" + vbTab + Str(AccessTime) + vbNewLine
   s = s + "Write Time: " + vbTab + Str(LastWriteTime) + vbNewLine
   s = s + "File Size: " + vbTab + Str(uFileSize) + vbNewLine
   MsgBox s, , "FTP Browse"
End Sub

10.

Run your program to test it.