Android Question How do you abort an FTP operation?

wjl2

Member
Licensed User
Longtime User
I'm scanning a number of machines to perform FTP downloads from them. The machines I'm looking at can be in any of three states:

1. Not be there. Powered down, off the net, etc.
2. There, but no FTP server running.
3. There with the FTP server running.

I have
DIM FTP As FTP
DIM FTP_IP As String
DIM FTP_UN As String
DIM FTP_PW As String
in Process_Globals

Then for each machine I fill in FTP_IP, FTP_UN and FTP_PW then do this:

FTP.Initialize ("FTP", FTP_IP, 21, FTP_UN, FTP_PW)
FTP.Download("Controller.txt", False, File.DirInternal, "Controller.txt")

Then wait for FTP_DownloadCompleted to fire.

In case 1, it eventually does, fails and I can move on to the next machine.

In case 3, it eventually does, fails or succeeds and again I can move on to the next machine.

But in case 2, FTP_DownloadCompleted never fires.

I figured, "no sweat." I'll set up some code to time out, close FTP (Close or CloseNow) and move on to the next machine. The code works, in the sense that the time out occurs and it does what I want. But it does not work in the sense that when it then times out on all future attempts to all machines, including those in case 3. I gather this is because Close and CloseNow don't really work (even though IsInitialized goes to False) until FTP_DownloadComplete fires. Which it never does in case 2.

It appears that even though you can initialize the FTP object for a new server, it's really stuck internally waiting for an event from the earlier machine that never fires.

I tried using something more benign, send the "binary" command. This is fine for case 1 and case 3, but FTP_CommandCompleted never fires for case 2.

What I need, it seems, is a way to abort operations that may be in flight. Is there a way to do that?

- wjl2
 

wjl2

Member
Licensed User
Longtime User
You said the DownloadCompleted didn't fire, you did not say anything about DownloadProgress. DownloadProgress should fire if the FTP process starts. If it does not start, you do not need to stop it.
No, I didn't. As may be, it doesn't fire either. Note that if I do a SendCommand instead the FTP_CommandCompleted event also never fires when the machine exists but has no FTP server.

What I do know is that after I've tried to do a download from an existing machine that does not have an FTP server running on it, the FTP object used to make that attempt is "stuck." Even after a Close or CloseNow and an Initialize for a different machine, it will never fire FTP_DownloadCompleted or FTP_DownloadProgress whether that other machine is there or not, or has an FTP server running or not.

I'm not sure what "start" and "stop" mean in this context. Since I did (and do) not understand how the FTP object works internally, I chose the word "abort" to be sort of all encompassing.
 
Upvote 0

wjl2

Member
Licensed User
Longtime User
Add this code just after you try to Initialize the FTP, send it to the log and see if it returns false, if so you can use it:

Log(FTP.IsInitialized)
Yeah, I tried that.

I put them before after Close, CloseNow and Initialize. They all say True before Close and CloseNow and False after and always say False before Initialize and True after. The FTP object is still unusable after the attempt to download or command with a machine that's running but has no FTP server active on it.

I think I understand how it's supposed to work. But it doesn't seem to do what one would expect in the machine present but FTP server not scenario. I was expecting to get FTP_DownloadCompleted with Success=False. The FTP object itself seems corrupted or stuck or otherwise mangled and never fires an event again, even when Initialized for a different IP, and even one where there is a machine and an FTP server running.

OK, now here's something new. I created another FTP object and, when the scenario noted occurs, used that for the next attempt rather than the one that had never fired an event. The new object works. No surprise. But after that I left the Android running and went to get something to eat. Upon returning I find:

libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)

in the log.

This does not occur when I do an Initialize on the FTP object that failed to fire an event. A clue?
 
Upvote 0

wjl2

Member
Licensed User
Longtime User
You should call Dim again if you want to reuse the object.
Well, that's a new thought for me. I'd never thought of "Dim" as being executable. So, how would one do this? The original "Dim" is in Sub Process Globals. Do you mean just do it again before the initialize? Like this:

Dim FTP as FTP
FTP.Initialize ("FTP", FTP_IP, 21, FTP_UN, FTP_PW)
FTP.Download("Controller.txt", False, File.DirInternal, "Controller.txt")

I'll try it a bit later today when I'm back on the project.
 
Upvote 0

wjl2

Member
Licensed User
Longtime User
Well, that's a new thought for me. I'd never thought of "Dim" as being executable. So, how would one do this? The original "Dim" is in Sub Process Globals. Do you mean just do it again before the initialize? Like this:

Dim FTP as FTP
FTP.Initialize ("FTP", FTP_IP, 21, FTP_UN, FTP_PW)
FTP.Download("Controller.txt", False, File.DirInternal, "Controller.txt")

I'll try it a bit later today when I'm back on the project.
That worked. Thank you.
 
Upvote 0
Top