Android Question test FTP connection b4x

Uniko Sistemi srl

Active Member
Licensed User
Hi everyone
I need to know if there is a way to know if the connection made to an FTP was successful. because if I try to put the wrong FTP address and execute FTP1.Initialize with all the relative parameters, I don't get any response to know if I'm connected to the FTP server or not....
This is because I would like to test if the FTP server is online before starting to transfer or read data...
I tried to PING but it takes too long...
Is there a way?
A thousand thanks
 

teddybear

Well-Known Member
Licensed User
FTP1.Initialize doesn't connect to the ftpserver. you can use FTP1.List(".") to check whether the ftpserver has been connected. if a wrong address is given, it will take 120s for timeout.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
Try:
B4X:
Dim ftp As FTP
ftp.Initialize("ftp", "ftp.domain.com", 21, "user", "password")
Dim sf As Object = ftp.SendCommand("ACCT", Null)
Wait For (sf) ftp_CommandCompleted (Command As String, Success As Boolean, ReplyCode As Int, ReplyString As String)
Log(Command & "->" & Success & "->" & ReplyCode & "->" & ReplyString)


edit: I am not familiar with FTP but maybe can try some commands like NOOP, PWD or STAT :)

 
Last edited:
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
A similar question was asked a few weeks ago. This was my suggestion . . .

1. Set the FTP timeout to, say, 200msec.
2. Try to send a dummy test file, just a few bytes.
3. If the FTP link times out you can tell that you do not have a connection.
4. If the dummy file transfer succeeds reset the timeout to something sensible, say 5000.

Here is a link.

I tried to PING but it takes too long...

I am not sure what you mean by "too long".
 
Last edited:
Upvote 0

Uniko Sistemi srl

Active Member
Licensed User
A similar question was asked a few weeks ago. This was my suggestion . . .

1. Set the FTP timeout to, say, 200msec.
2. Try to send a dummy test file, just a few bytes.
3. If the FTP link times out you can tell that you do not have a connection.
4. If the dummy file transfer succeeds reset the timeout to something sensible, say 5000.

Here is a link.



I am not sure what you mean by "too long".

thanks i tried to use your example, i just need to figure out where i can find FTPLINK because it's a library that i probably miss Thank you
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
i just need to figure out where i can find FTPLINK because it's a library that i probably miss
Yes - it is not easy to find. In case you have not found it yet, FTP is part of the Net library.
 
Upvote 0
Top