Overview (FTP)
Close (FTP)
CreateDirectory (FTP)
DeleteFile (FTP)
GetCurrentDirectory (FTP)
GetEntries (FTP)
GetFile (FTP)
IsFTPConnected (FTP)
New1 (FTP)
Open (FTP)
PutFile (FTP)
RenameFile (FTP)
SetCurrentDirectory (FTP)
Overview (FTP) Top
Using the FTP library you can connect the device or desktop to a ftp server and download or upload from it.
The device / desktop should be connected to the internet.
Note that connecting to an ftp library when the device is connected to the internet using Activesync is not recommended and may not work properly.
Working with this library is pretty simple.
First add a reference to this library using the Components dialog.
Add an object of that type using Tools - Add Object.
Initialize the object with the New1 method.
Connect to the ftp server with the Open method (include user user name and password if necessary).
Upload or download files.
Close the connection with the Close method.
Example:
This example requires an ftp object named ftp, a table named table1 and a button named btnDownload.
Sub Globals
dim entries(0) 'This array will be filled by the GetEntries method.
End Sub
Sub App_Start
Form1.Show
ftp.New1
ftp.Open("ftp.ftpplanet.com","","") 'No user name or password required here.
ftp.SetCurrentDirectory("images")
table1.AddCol(cString,"name",60)
table1.AddCol(cString,"date",60)
table1.AddCol(cNumber,"size",60)
FillEntries
End Sub
Sub FillEntries 'Fills the table with the directories and files
entries() = ftp.GetEntries("",true) 'Get all subdirectories first.
for i = 0 to arraylen(entries())-1 step 3 'Each entry includes 3 values: name, date (ticks) and size.
table1.AddRow(entries(i),date(entries(i+1)),entries(i+2))
next
entries() = ftp.GetEntries("",false) 'Get all files now.
for i = 0 to arraylen(entries())-1 step 3
table1.AddRow(entries(i),date(entries(i+1)),entries(i+2))
next
End Sub
Sub btnDownload_Click
WaitCursor(true)
name = table1.Cell("name",table1.SelectedRow)
ftp.GetFile(name,AppPath & "\" & name)
WaitCursor(false)
End Sub
Sub Form1_Close
ftp.Close 'Close the connection.
End Sub
Close (FTP) Top
Closes the connection.
Syntax: Close
CreateDirectory (FTP) Top
Creates a new directory (inside the current one).
Syntax: CreateDirectory (Dir As String)
Example:
ftp.CreateDirectory("data")
DeleteFile (FTP) Top
Deletes a file from the server.
Syntax: DeleteFile (SrcFile As String)
SrcFile - The file that will be deleted.
Example:
ftp.DeleteFile ("a.txt")
GetCurrentDirectory (FTP) Top
Gets the current directory name.
Syntax: GetCurrentDirectory
GetEntries (FTP) Top
Returns an array filled with the files or subdirectories in the current directory.
The array includes the entry name, date and size.
Syntax: GetEntries (Filter As String, Dir As Boolean) As String()
Filter - Allows you to filter the entries returned. The filter string can include '*' and '?'.
Dir - If true then only subdirectories will be returned, otherwise only files will be returned.
The date is returned as ticks, which means you should use the Date keyword to get the date formatted as a string.
The array format is:
array(0) - entry #1 name
array(1) - entry #1 date
array(2) - entry #1 size (0 for directories).
array(3) - entry #2 name
...
array(3*n-3) - entry #n name
array(3*n-2) - entry #n date
array(3*n-1) - entry #n size
Example:
dim entries(0)
entries() = ftp.GetEntries("image00?_*.*",false)
GetFile (FTP) Top
Downloads a file from the server.
Syntax: GetFile (SrcFile As String, DstFile As String)
SrcFile - The name of the file on the server.
DstFile - The path and name of the target file on the device / desktop.
Example:
ftp.GetFile("image001.jpg",AppPath & "\image001.jpg")
IsFTPConnected (FTP) Top
Returns true if there is an open connection.
Syntax: IsFTPConnected.
New1 (FTP) Top
Initializes an ftp object.
Syntax: New1
Open (FTP) Top
Creates a connection to an ftp server.
Syntax: Open (URL As String, UserName As String, Password As String)
If the server supports anonymous login then you can leave the UserName and Password empty ("").
Example:
ftp.Open ("ftp.myftp.com","","")
PutFile (FTP) Top
Uploads a file to the ftp server.
Syntax: PutFile (SrcFile As String, DstFile As String)
SrcFile - The name and path of the file on the device / desktop.
DstFile - The name of the target file on the server.
Example:
ftp.PutFile (AppPath & "\image001.jpg","Image001.jpg")
RenameFile (FTP) Top
Renames a file on the server.
Syntax: RenameFile (SrcFile As String, DestFile As String)
SrcFile - The old name.
DestFile - The new name.
Example:
ftp.RenameFile ("a.txt","b.txt")
SetCurrentDirectory (FTP) Top
Changes the current working directory (on the server).
Syntax: SetCurrentDirectory (Dir As String)
Dir - One of the subdirectories in the current directory.
You can use ".." to go up one level.
Example:
ftp.SetCurrentDirectory ("data")