SamLogic Internet Components - Home
ActiveX: SLFTP      (Filename: SLFTP.OCX)


SLFTP is an ActiveX component that can be used to communicate with an FTP server. You can with this control for example download or upload files, create or remove directories, list directories, get information about files (for example the file size) etc.
 
 
Properties
 
Name Type Description
IsConnected Boolean Indicates if there is a connection with the FTP server. If there is a connection, this property returns True. If there is no connection, this property returns False.
 
Password String Specifies the password to use when connecting to the FTP server.
 
RemotePort Long Specifies the port number to use when connecting to the FTP server. The default value for this property is 21.
 
RemoteServer String Specifies the FTP server name. 
 
Username String Specifies the user name to use when connecting to the FTP server.
 
 
Methods
 
Before you use any of the FTP commands in the SLFTP control you must call the OpenConnection or OpenSyncConnection method to open a connection to the FTP server. When you don't need to communicate with the FTP server anymore you must call CloseConnection to close the connection. If an error occurs using any of the methods in this control you can call the GetLastError method to obtain the error code. Some errors can also be obtained as a text message by calling the GetErrorMessage method.
 
 
OpenConnection
() As Boolean

Opens a connection to an FTP server. The RemoteServer, RemotePort, Password and Username properties must have proper values set before this method is called. The method returns True if successful, or False otherwise.

OpenSyncConnection (sAgent As String, AccessType As Long, sProxyName As String) As Boolean

Opens a connection to an FTP server. sAgent specifies a string that contains the name of the application and AccessType specifies the type of access required. Can be one of the following values:

0 = Use registry configuration
1 = Direct to net
3 = Via named proxy
4 = Prevent using java/script/INS

The sProxyName parameter specifies a string that contains the name of the proxy server to use if proxy access is needed. The RemoteServer, RemotePort, Password and Username properties must have proper values set before this method is called. The method returns True if successful, or False otherwise.

CloseConnection () As Boolean

Closes the connection to the FTP server. Returns True if successful, or False otherwise.
 


CreateDir (sDir As String) As Boolean

Creates a directory, specifies by sDir, on the FTP server. Returns True if successful, or False otherwise.

DelFile (sFilename As String) As Boolean

Deletes a file on the FTP server. The sFilename parameter specifies the file to delete. The method returns True if successful, or False otherwise.

DownloadFile (sRemoteFilename As String, sLocalFilename As String) As Boolean

Downloads a file from the FTP server to the local client. The sRemoteFilename parameter specifies the filename at the FTP server and the sLocalFilename parameter specifies the filename at the local client. The method returns True if successful, or False otherwise.

FileExists (sFilename As String) As Boolean

Checks if a file exists on the FTP server. The sFilename parameter specifies the file to check. Returns True if the file exists, or False otherwise.

GetCurDir () As String

Returns the current directory on the FTP server. If there is an error the method returns an empty string ("").

GetErrorMessage () As String

Returns the last error as a text message if an error occurred when running an FTP command.

GetFileDateTime (sFilename As String) As String

Returns the file date and time for a file on the FTP server. The sFilename parameter specifies the file to examine. If there is an error the method returns an empty string ("").

GetFileSize (sFilename As String) As Long

Returns the size (in bytes) of a file on the FTP server. The sFilename parameter specifies the file to examine. If there is an error the method returns 0.

GetLastError () As Long

Returns an error code for the last error that occurred in the control.
A list of possible error codes is available here.

ListDir (sDir As String, sFileSpec As String) As String

Lists the contents of a directory on the FTP server. The sDir parameter specifies the directory to list and the sFileSpec parameter specifies a group of files to list. You specify the file group by using wildcard characters, for example "*.txt" or "*.*". The method returns the content if the operation was successful. If more than one filename is found they are separated with a "|" character in the return string. If there is an error the method returns an empty string ("").

ListDirectoriesInDir (sDir As String) As String
 
Lists all directories in a specified directory. The sDir parameter specifies the directory to examine. If more than one directory is found they are separated with a "|" character in the return string. If there is an error the method returns an empty string ("").

RemoveDir (sDir As String) As Boolean

Removes a directory from the FTP server. sDir specifies the directory to remove. Returns True if successful, or False otherwise.

SetCurDir (sDir As String) As Boolean

Sets current directory on the FTP server to the name specified by sDir. Returns True if successful, or False otherwise.

StoreFile (sLocalFilename As String, sRemoteFilename As String) As Boolean

Transfers a file from the local computer to the FTP server. The sLocalFilename parameter specifies the source filename and the sRemoteFilename parameter specifies the destination filename. The method returns True if successful, or False otherwise.
 

 
 
Example
 
Dim bStatus As Boolean
 
SLFTP1.RemoteServer = "ftp.test.com"             ' Specify the FTP server
SLFTP1.Username = "SamLogic"                    
' Specify the username
SLFTP1.Password = "test"                 
       ' Specify the password
 
If SLFTP1.OpenConnection() Then                  ' Open a connection to the FTP Server
    If SLFTP1.SetCurDir("/www") Then            
' Set current directory to "/www"
        If SLFTP1.FileExists("index.htm") Then  
' Check that the file exists
            bStatus = SLFTP1.DownloadFile("index.htm", "c:\temp\index.htm")
' Download file
        End If
    End If
    SLFTP1.CloseConnection
End If
 
 
< Go back
 
 
SamLogic