Mar 5, 2013 Replies: 241 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: Code: 'Call the command like this: FTP.FileOrFolderExist("plane.jpg" , "test/files", False) Code: '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! REQUIRES: B4A 2.5 + Copy the FTP_Auto.jar & FTP_Auto.xml files to the Extra Libraries folder. FTP_Auto 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. Example: DeleteFile("public/pictures/airplane1.jpg") 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 Example: 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. Example: 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. Example: 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. Example: MakeDir("test") MakeDir("test/datafolder") 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. Example: 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 Permissions: ◦android.permission.ACCESS_WIFI_STATE ◦android.permission.INTERNET Attachments Automated FTP Version 1.05.zip Automated FTP Version 1.05.zip 14.8 KB · Views: 1,561 Automated FTP Version 1.06.zip Automated FTP Version 1.06.zip 14.3 KB · Views: 2,151 FTP_Auto_Sample_Code_1.06.zip FTP_Auto_Sample_Code_1.06.zip 322.9 KB · Views: 2,349 Last edited: Mar 24, 2014 Click to expand...
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: Code: 'Call the command like this: FTP.FileOrFolderExist("plane.jpg" , "test/files", False) Code: '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! REQUIRES: B4A 2.5 + Copy the FTP_Auto.jar & FTP_Auto.xml files to the Extra Libraries folder. FTP_Auto 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. Example: DeleteFile("public/pictures/airplane1.jpg") 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 Example: 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. Example: 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. Example: 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. Example: MakeDir("test") MakeDir("test/datafolder") 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. Example: 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 Permissions: ◦android.permission.ACCESS_WIFI_STATE ◦android.permission.INTERNET
margret Well-Known Member Licensed User Longtime User Dec 13, 2013 #141 This will be determined by your server and not the app.
C Claudio57 Member Licensed User Longtime User Jan 7, 2014 #142 Hello Margret. I saw your library Automated FTP but I could not find the sample code. I am a beginner and I need to understand the example. Thank you.
Hello Margret. I saw your library Automated FTP but I could not find the sample code. I am a beginner and I need to understand the example. Thank you.
margret Well-Known Member Licensed User Longtime User Jan 9, 2014 #143 In the B4A editor, if you load this library and Dim a variable like. Dim MFTP as FTP_Auto "Now when you type MFTP." Once you press the period, it will give you a list of the functions and their syntax. I have not written any sample code as I have had very limited time.
In the B4A editor, if you load this library and Dim a variable like. Dim MFTP as FTP_Auto "Now when you type MFTP." Once you press the period, it will give you a list of the functions and their syntax. I have not written any sample code as I have had very limited time.
S shashkiranr Active Member Licensed User Longtime User Jan 11, 2014 #144 Hi Margret, how do you connect to ur local host? i have xampp installed on my computer. Kindly let me know. Regards, SK
Hi Margret, how do you connect to ur local host? i have xampp installed on my computer. Kindly let me know. Regards, SK
S shashkiranr Active Member Licensed User Longtime User Jan 12, 2014 #145 Hi Margret, I succeeded in transferring a file to the server however i am facing the below issues. 1. im using the following initialization code Code: FTP.Initialize(Activity,Me,"ftp.xxx.com","fxxxx","xxxx",21,False,True) FTP.SetStealthOn(True) FTP.SetCompletedUploadDialog(True,"Files Uploaded Successfully") but still the progress bar is shown when the file is uploaded to the server. 2. For uploading two or more files i am using Code: FTP.UploadFileSet("",file_name,False) where filename is an array containing the loacation of the files in the local. This is not working since i get an arrayindexoutofbounds exception. Should we define filename as array as string ("","") ? Kindly let me know. Regards, SK
Hi Margret, I succeeded in transferring a file to the server however i am facing the below issues. 1. im using the following initialization code Code: FTP.Initialize(Activity,Me,"ftp.xxx.com","fxxxx","xxxx",21,False,True) FTP.SetStealthOn(True) FTP.SetCompletedUploadDialog(True,"Files Uploaded Successfully") but still the progress bar is shown when the file is uploaded to the server. 2. For uploading two or more files i am using Code: FTP.UploadFileSet("",file_name,False) where filename is an array containing the loacation of the files in the local. This is not working since i get an arrayindexoutofbounds exception. Should we define filename as array as string ("","") ? Kindly let me know. Regards, SK
margret Well-Known Member Licensed User Longtime User Jan 12, 2014 #146 Look at the bottom of page 4 and downlod the newest version of this library, version 1.03. It should correct this issue. And YES, you should use: FTP.UploadFileSet("", Array As String(file_name), False)
Look at the bottom of page 4 and downlod the newest version of this library, version 1.03. It should correct this issue. And YES, you should use: FTP.UploadFileSet("", Array As String(file_name), False)
S shashkiranr Active Member Licensed User Longtime User Jan 12, 2014 #147 Thanks Margret, Any idea how to Convert file_name() as string to Array as String ("","") Regards, SK
margret Well-Known Member Licensed User Longtime User Jan 12, 2014 #148 Ok, I think I told you wrong. I went back and looked at this again. Have you tried: Code: FTP.UploadFileSet("", file_name(), False)
Ok, I think I told you wrong. I went back and looked at this again. Have you tried: Code: FTP.UploadFileSet("", file_name(), False)
S shashkiranr Active Member Licensed User Longtime User Jan 12, 2014 #149 yes i have tried Code: FTP.UploadFileSet("",file_name,False) since file_name is defined as an Array of String but it is not working getting indexoutfbounds exception.
yes i have tried Code: FTP.UploadFileSet("",file_name,False) since file_name is defined as an Array of String but it is not working getting indexoutfbounds exception.
margret Well-Known Member Licensed User Longtime User Jan 12, 2014 #150 Did you try with the () after file_name? Be sure to add the ().
S shashkiranr Active Member Licensed User Longtime User Jan 12, 2014 #151 yes i get a warning saying object converted to string. this must be a programming mistake. should i still ignore the warning and go ahead??
yes i get a warning saying object converted to string. this must be a programming mistake. should i still ignore the warning and go ahead??
margret Well-Known Member Licensed User Longtime User Jan 12, 2014 #152 Yes, I would try it even with the warning. The function is looking for a string array to be passed to it. If your array is a string array, this should work without any problems. You can also test it by hard coding a few items just to test. You may also want to log the array elements right before this command, just to confirm what is in each element and it's size.
Yes, I would try it even with the warning. The function is looking for a string array to be passed to it. If your array is a string array, this should work without any problems. You can also test it by hard coding a few items just to test. You may also want to log the array elements right before this command, just to confirm what is in each element and it's size.
margret Well-Known Member Licensed User Longtime User Jan 12, 2014 #153 shashkiranr said: yes i have tried Code: FTP.UploadFileSet("",file_name,False) since file_name is defined as an Array of String but it is not working getting indexoutfbounds exception. Click to expand... As you have listed above, this is the correct format. I just did it in a project I am working on. So, we need to look for something else or something about the array that is causing this error. Make sure you don't have any other subs or variables named file_name. If file_name is built in another sub, it should also be a Global variable. Last edited: Jan 12, 2014
shashkiranr said: yes i have tried Code: FTP.UploadFileSet("",file_name,False) since file_name is defined as an Array of String but it is not working getting indexoutfbounds exception. Click to expand... As you have listed above, this is the correct format. I just did it in a project I am working on. So, we need to look for something else or something about the array that is causing this error. Make sure you don't have any other subs or variables named file_name. If file_name is built in another sub, it should also be a Global variable.
S shashkiranr Active Member Licensed User Longtime User Jan 13, 2014 #154 Hi Margret, I tried () after file_name but not working. it gives a missing parameter error. Any workaround since i need to upload multiple files at once. Regards, SK
Hi Margret, I tried () after file_name but not working. it gives a missing parameter error. Any workaround since i need to upload multiple files at once. Regards, SK
margret Well-Known Member Licensed User Longtime User Jan 13, 2014 #155 Read my previous post. The () are not needed. Can you post your code, this should be working. As I stated in the previous post, I used it and did not have a problem.
Read my previous post. The () are not needed. Can you post your code, this should be working. As I stated in the previous post, I used it and did not have a problem.
GMan Well-Known Member Licensed User Longtime User Jan 24, 2014 #156 Hoi margret, nice lib - would be nice if you update the 1st post with the 1.03 lib
margret Well-Known Member Licensed User Longtime User Jan 24, 2014 #157 GMan said: Hoi margret, nice lib - would be nice if you update the 1st post with the 1.03 lib Click to expand... Post #1 has been updated with version 1.05. Thanks for the reminder.
GMan said: Hoi margret, nice lib - would be nice if you update the 1st post with the 1.03 lib Click to expand... Post #1 has been updated with version 1.05. Thanks for the reminder.
GMan Well-Known Member Licensed User Longtime User Jan 24, 2014 #158 De nada Is there a way to combine file_mask and specified file ? And if i try 1.05 my App crashes
margret Well-Known Member Licensed User Longtime User Jan 24, 2014 #159 At the current time there is not. I may look at this when I get some more time. About your app crashing, what error does it give? Check the parameters in the Initialize command. I think the newer version has some extra parameters you need to pass.
At the current time there is not. I may look at this when I get some more time. About your app crashing, what error does it give? Check the parameters in the Initialize command. I think the newer version has some extra parameters you need to pass.
GMan Well-Known Member Licensed User Longtime User Jan 24, 2014 #160 It crashes with no error message but "App was ended". OK, will have a look to the additinonal parameters...tried it (of course) only be changing the lib
It crashes with no error message but "App was ended". OK, will have a look to the additinonal parameters...tried it (of course) only be changing the lib