B4A Library Automated FTP Library

New Automated FTP Library

UPDATED 3-24-2014 - Version 1.06 changes the display scale and should look better on the larger display of a tablet. A sample project is now included which shows how to use this library. The sample code requires B4A 3.2+. You can open and view the code with older versions but it will not run because of the newer layout files.

UPDATED 1-24-2014 - Version 1.05 adds a new function for checking for files or folders. It also contains a few other small fixes.
The new command works for Files or Folders. If the last parameter is set to TRUE, it will look for folders, if the last parameter is set to FALSE it will look for files. Because the code runs in the background and is modeless you must have a callback sub in the calling module. Code samples below:

'Call the command like this:
FTP.FileOrFolderExist("plane.jpg" , "test/files", False)

'Callback sub in calling module:
Sub FTP_FileExist(Found As Boolean)
    If Found Then Log("True") Else Log("False")
End Sub

UPDATED 4-2-2013 - Version 1.02 Corrects an issue where PassiveMode was not working and also corrects an issue where UploadFileSet would not work from File.DirInternal.

Automates the process of sending and receiving files using FTP with Wildcards & File Masks. Version 1.02 is attached. Please post/report back any issues you find, etc.

This library has progress bars for Each File and overall progress. It handles wildcards and multi file types at the same time. Issue one command and transfer multiple files and multiple types! Change the colors, text size and words of all objects on the Progress Dialog to fit the look of your app. Also works in Stealth Mode!

Copy the FTP_Auto.jar & FTP_Auto.xml files to the Extra Libraries folder.


  • Close
    Completes the current Que with any files left to process and then
    closes the connection.
  • CloseNow
    Closes the connection and all other files in the Que are
    ignored and the process is terminated.
  • DeleteFile (DeletePathAndFile As String)
    Deletes a single file from the server.

  • DeleteFileSet (VerifyBeforeDelete As Boolean)
    Delete the lastest FileSet in memory from the server.
    If you used a Mask to download a set of files, this function
    will delelete all files in that last set.
    NOTICE: use with care.
  • DownLoadFile (LocalPath As String, ServerPath As String, FileName As String, Delete_FromServer As Boolean)
    Downloads a selected file from the FTP server and optionally deletes the file after successful download

    DownLoadFile("/mnt/sdcard/pictures/", "public/downloads/", "airplane.jpg", False)
  • DownloadFileSet (LocalPath As String, Files_Path_And_Mask() As String, Delete_FromServer As Boolean)
    Retrieves a list of files from the server matching the Mask(s) passed to Files_Path_And_Mask() array.
    You should include the full server path in the Mask. It will then download these files to
    the Folder passed in LocalPath. Files_Path_And_Mask() can contain one entry or however many is needed.

    DownloadFileSet(File.DirInternal, Array As String("SM*.txt", "public/pictures/pla*.jpg"), False)
  • IsInitialized As Boolean
    Tests whether the object has been initialized.
  • Initialize (Activity As Activity, CalledFrom As Object, FTP_Site As String, UserName As String, PassWord As String, PortNumber As Int, ShowMessages As Boolean, UsePassiveMode As Boolean) As String
    Initializes the object for use. If True is passed for ShowMessages, additional
    messages will be displayed throughout the process. Use the keywords "Activity"
    and "Me" For the first two parameters.

    Initialize(Activity, Me, "ftp.yourdomain.com", "userName", "PassWord", "Port", True, False)
  • LastDownloadStats ( As ) As String
    Shows a popup window with the detials of the latest Download(s).
  • LastProcessSuccessful As Boolean
    Returns True if the last Upload or Download process was successful, otherwise returns False.
  • LastUploadStats ( As ) As String
    Show a popup window with details of the latest Upload(s).
  • MakeDir (DirectoryName As String)
    Makes a directory on the FTP server. Does nothing if the directory already exist.
    If you want to make a directory in the root of the server and then a directory under
    it, you must issue the command twice.

  • RemoveDir (DirectoryName As String)
    Removes selected directory from the FTP server
  • SetColors (HeadingColor As Int, TotalProgressColor As Int, FileTextColor As Int, PanelBackgroundColor As Int, FrameColor As Int)
    Used to set colors of each Item in the status dialog.
    NOTE: Passing 0 for any argument with leave that item unchanged
  • SetCompletedDownloadDialog (ShowCompletedDialog As Boolean, DialogText As String)
    If ShowCompletedDialog=True, it will show a dialog after the download process is completed.
  • SetCompletedUploadDialog (ShowCompletedDialog As Boolean, DialogText As String)
    If ShowCompletedDialog=True, it will show a dialog after the upload process is completed.
  • SetProcessCompleteOn (ProcessCompleteOn As Boolean)
    Use this function to determine by code when the Upload or Download is finished.
    The calling Activity must contain a sub named FTP_ProcessComplete. If your calling
    Activity includes this sub and you set this function to True, then the sub will
    be called as soon as the process has completed. EXAMPLE:

    'Add this sub to calling Activity
    Sub FTP_ProcessComplete
    'Your code here...
    End Sub
  • SetStealthOn (UseStealth As Boolean)
    If set to True, no progress box will be displayed during the file
    transfer. If False the progress dialog will show during the file
    transfers. The default is False.
  • SetStickyOn (MakeSticky As Boolean)
    If set to True, the progress box will stay on the screen until
    the user taps the Done button, otherwise the progress box will close
    as soon as the transfer is complete. The default is False.
  • SetText (HeaderDownLoadText As String, HeaderUploadText As String, TotalProgressText As String, FileProgressText As String, ButtonCancelText As String, ButtonDoneText As String)
    Used to set the Text of the Item's status display.
    NOTE: May be used for different language, etc.
  • SetTextSize (HeaderTextSize As Int, TotalProgressTextSize As Int, FileProgressTextSize As Int, CancelAndDoneTextSize As Int)
    Used to set the Text size of the Item's Text in the status dialog.
    NOTE: Passing 0 for any argument with leave that item unchanged
  • UpLoadFile (LocalPath As String, ServerPath As String, FileToSend As String)
    Uploads a single file passed in FileToSend

    Example: UpLoadFile("/mnt/sdcard/pictures", "uploads/pictures", "vacation.jpg")
  • UploadFileSet (ServerPath As String, Files_Path_And_Mask() As String, DeleteFileFromLocalDevice As Boolean)
    Retrieves a list of files from the local device. The Files_Path_And_Mask() array should contain the full
    path to the local devices files. It will then upload these files to the server.
    Files_Path_And_Mask() array can contain one entry or however many is needed.

    UploadFileSet("uploads/pictures/", Array As String("/mnt/pictures/VA*.jpg", "/mnt/sdcard/backups/contact*.dat"), False)
  • WiFi_IsConnected As Boolean
    Check if Wifi is connected
    Returns True if connected otherwise returns False



  • Automated FTP Version 1.05.zip
    14.8 KB · Views: 582
  • Automated FTP Version 1.06.zip
    14.3 KB · Views: 1,256
  • FTP_Auto_Sample_Code_1.06.zip
    322.9 KB · Views: 1,420
Last edited:


Well-Known Member
Licensed User
My compliments @margret !
I'm planning a feature that let users to send a file from device to device.

This library implements ftp client.
There is a ftp server 4 Android that let to customize (programmatically) the destination directory and the file replace feature?

The target is to allow a user to send a file to another device in a default directory and automatically replace the file with the same name in the target device.


Well-Known Member
Licensed User
@margret I'm trying your sample code.
I got a connection refused error.
The server support Anonymous login. To initialize an anonymous connection I must put user : Anonymous and password : ""?


Licensed User
Version 1.06 and FTP_AutoSample:

If the FTP server is not reachable, upload files (set or single) do not return any error and remain on hold.

By setting for example: FTP.SetText( "RICEZIONE","INVIO","Totale trasferimento", "Trasferito", "ANNULLA","Chiudi") ,
the label FileProgressText becomes: "Trasferito: Downloaded" (and file size)


Licensed User
Version 1.06 and FTP_AutoSample:

If during the "Upload file set" or "Download file set" pressed "Cancel" subsequent "Upload or Download file set" to stop working after the first file


Licensed User
Hi I want to upload three files:

That is my code:

Dim Upload(3) as String
Upload(0) = "/storage/extSdCard/Content/CFG/test.cfg"
Upload(1) = "/storage/extSdCard/Content/GFX/test.gfx"
Upload(2) = "/storage/extSdCard/Content//INI/test.ini"
FTP.UploadFileSet("Upload", Upload, False)

I will get the follwoing error:
Error occurred on line: 1859 (main)
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at ftp.auto.lib.ftp_auto._vv1(ftp_auto.java:256)
at ftp.auto.lib.ftp_auto._vvvvvvv1(ftp_auto.java:1617)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:680)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:308)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java:4640)
at android.view.View$PerformClick.run(View.java:19421)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)

If I split the string in Dir and Name and use this command:
FTP.UploadFile(Dir(0), "Upload", Name(0))
The file will be uploaded without any problems.

What's wrong?

Massimo Linossi

Licensed User
Hello Margret.
First of all many compliments for your library, works perfectly.
I want to ask if there is some place where I can translate the strings in the little popup message that
is shown below the main FTP dialog. Strings like "All names retrieved...", "Getting names from server..."
Thanks a lot.


Well-Known Member
Licensed User
Hello Margret.

I see that there is a Stealth mode. But is there a way to just download/upload without ANY dialogs?



Licensed User
I iam trying to include FTP_AUTO on my project but i recive This message: Cannot acess activity object from sub Process_Globals... why? :,(

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

Dim dbug As Boolean : dbug = False
Dim AppName As String : AppName = "DISVEN 0.1"
Dim AppDB As String : AppDB = "disven.db"

Dim FTPA As FTP_Auto
End Sub

thanks in advance


Licensed User
Hi Margret.

Great Library...

If I request DownloadFileSet and there are no files to download I get a message that pops up stating 'No Files Found' would it be possible to get this as a call back event rather than a pop up message?


luciano deri

Active Member
Licensed User
Have you an example of use?
how to test the connection to the ftp server before Dowload, Upload ....
Best Regards
Hello Margret, is ready now this function ?
In the DownloadFileSet is possible set the text of automatic toast message?


Active Member
Licensed User
java.lang.RuntimeException:Error uploading file.
500 I wont's open a connection to (only to

I have set the FTP to Makedir and then upload a file. The folders are created on the FTP but then the above error message popped and the uploading cannot be done.
Anyone can help?

Vinay Chaddha

New Member
Licensed User
Hi, can you please tell me how to handle event of "Cancel Button" in progress dialog while uploading..


  • question.png
    16 KB · Views: 71


Licensed User
can we use this library in SERVICE MODULE?

Initialize (Activity AsActivity, CalledFrom As Object, FTP_Site AsString, UserName AsString, PassWord AsString, PortNumber AsInt, ShowMessages AsBoolean, UsePassiveMode AsBoolean) As String

i want to use in service modules. so acctivity as activity?