Android Tutorial Android FTP tutorial

Status
Not open for further replies.

Rusty

Well-Known Member
Licensed User
Longtime User
Erel,
With the ABFTP lib, you could detect the connection was or was not made with


Dim ABFT As ABFTP
abft.ABFTPConnect(txtftp, txtport,txtlogin, txtpassword)
WiFiAvailable = abft.ABFTPConnected
abft.ABFTPDisconnect

the ABFTPConnect returns true if the connection is made and false otherwise. With the FTP library, is there a similar capability? If so, how?
Thanks,
 

Rusty

Well-Known Member
Licensed User
Longtime User
Yes, I understand that part. The question is, how can I tell that there is no wireless connection available or that the wireless unit is not on or...? In other words, is there a way to tell that the connection failed?
My example is that my APP is being used in L.A. The place it was being used has a secured WiFi and the passphrase is not available, therefore the connection will fail. My ListFiles request is never satisfied causing delays. I would like to be able to detect the failure at or before the connection is attempted (and failed).
thanks Erel
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
If the connection fails then the Completed event will be raised and Success parameter will be False. You can get the error message by calling LastException.

You can issue a List command at the beginning just to test the connection.
This library manages all operations in the background to avoid blocking your program. This includes the connection. I preferred to keep the API simpler and implicitly connect as needed.
 

Rusty

Well-Known Member
Licensed User
Longtime User
Perfect! That's what I needed to know. I'll implement today.
Thanks
 

ppico

Member
Licensed User
Longtime User
I'm using this code:


el servidor ftp es "cerberus FTP server"
the error is when loading the file
the server receives the command, but after a few seconds stops
I am using the emulator



1.txt, Success=false

java.lang.RuntimeException: Error uploading file.
425 Unable to open the data connection

** Activity (main) Pause, UserClosed = true **
 
Last edited:

ppico

Member
Licensed User
Longtime User
2011-08-17 17:10:48]:COMMAND [ 1] - TYPE I
[2011-08-17 17:10:48]: REPLY [ 1] - 200 Type Binary

[2011-08-17 17:10:48]:COMMAND [ 1] - PORT 10,0,2,2,10,145
[2011-08-17 17:10:48]: REPLY [ 1] - 200 Port command received

[2011-08-17 17:10:48]:COMMAND [ 1] - STOR 1.txt
[2011-08-17 17:11:09]: ERROR [ 1] - Unable to connect : Se produjo un error durante el intento de conexión ya que la parte conectada no respondió adecuadamente tras un periodo de tiempo, o bien se produjo un error en la conexión establecida ya que el host conectado no ha podido responder.

[2011-08-17 17:11:09]:SUGGEST [ 1] - For help see Cerberus Cerberus FTP Server FAQ - Initial Setup
[2011-08-17 17:11:09]: REPLY [ 1] - 425 Unable to open the data connection

[2011-08-17 17:12:49]:CONNECT [ 1] - Connection timed out - Shutting down connection...
[2011-08-17 17:12:50]:CONNECT [ 1] - Connection terminated
 

bosscarnage

New Member
Licensed User
Longtime User
a newbie question :

I put both files ftp.jar and ftp.xml in my B4A libraries folder



but I still can't create a FTP object



Is there anything else to do in my project to get this library recognized ?

Thx
 

Fabrice La

Active Member
Licensed User
Longtime User
Error FTP Library

Hi,

In my project, the fact to check the FTP library (1.01) give me an compile error (Whithout to add anything in the program):

Compiling code. 0.18
Generating R file. 0.00
Compiling generated Java code. 0.97
Convert byte code - optimized dex. Error
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/apache/commons/net/DatagramSocketClient;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
at com.android.dx.dex.file.DexFile.add(DexFile.java:143)
at com.android.dx.command.dexer.Main.processClass(Main.java:372)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:346)
at com.android.dx.command.dexer.Main.access$400(Main.java:59)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:294)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
at com.android.dx.command.dexer.Main.processOne(Main.java:313)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:233)
at com.android.dx.command.dexer.Main.run(Main.java:185)
at com.android.dx.command.dexer.Main.main(Main.java:166)
at com.android.dx.command.Main.main(Main.java:90)
1 error; aborting
Standard dexer.
 

Fabrice La

Active Member
Licensed User
Longtime User
The library chesked are :
AHLocale 1.10
Camera 1.00
Core 1.57
Dioalogs 2.7
Licensing 1.00
Net 1.11
Phone 1.55
Reflection 1.8
SQL 1.02
StringUtils 1.02

If I add FTP 1.01 = Errors Compiling
 

Fabrice La

Active Member
Licensed User
Longtime User
Hi

Other problem :

if the system try to connect to ftp server I have a tempo of 20s. After this 20s
the program use FTP.closeNow
If I restart the connection the "success" is already "false" in
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)

I cant start to download.

I have to kill my appli and restart it to be able to try to download again.

It seems that the Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean) "Success" is stay at "false" .....

If you understand me
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…