FTP question

rfresh

Well-Known Member
Licensed User
Longtime User
I'm using FTP in my Main activity. Please confirm that I understand the following correctly:

1. FTP.Initialize goes in Activity_Create but not inside FirstTime?

2. In my Main Activity_Resume event I initiate a file download from my website but the FTP_DownloadCompleted event never fires. I set a break point in there and it never stops. When I start up my app I want it to download this file.

My Main Activity_Resume code:
Code: Copy
mShortFilename = "0.txt"
mLongFilename = "/public_html/remote/0.txt"
FTP1.DownloadFile(mLongFilename, True, mFilePath, mShortFilename)

In the debugger I see no errors so I don't know why the FTP_DownloadCompleted event does not stop at the break point?

3. FTP.Close should go in Activity_Pause?

Thank you...
 
I have used the FTP in all my apps and I do not use it in the Activity_Create. I call a sub when I wish to start the FTP:

Code: Copy
Sub FTP_Acti
   FTP.Initialize("FTP", "ftp.mydomain.com", m_port, m_user, m_pass)
   FTP_Start
End Sub

Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
    Log("Downloaded: /" & ServerPath & ", Success=" & Success)
    If Success = False Then 
      Log(LastException.Message)
      FTP_Acti
    End If
    ProgressDialogHide
End Sub

Sub FTP_Start
    ProgressDialogShow("NOTICE: Activating Movie Gallery...")
    FTP.DownloadFile(getfile, True, File.DirInternal, savefile)
End Sub
 
Upvote 0
I (finally found it) see in the FTP tutorial that FTP.Initialize is done in the Create FirstTime block (if you follow the tutorial).

So Margret, you don't ever use FTP.Close?

Going back to the FTP tutorial, if you elect to use FTP.Close then when you want to download again, you just call FTP.Download? You don't need to re-initialize if you used Close? I'm not clear on that.
 
Upvote 0
Yes, if you don't FTP.Close you can keep download / uploading as many files as you want. I do think there is a limit of 15 files in the que at any one time. If your are indeed done, you should use FTP.Close. However, you can see in the FTP_Acti, that I do reopen and re-initialize each time I call that sub.

I do close it before the user leaves the App. I think I have run into issues trying to download again after a FTP.Close without re-initializing the connection.
 
Upvote 0
FTP.List problems

I can not get to use FTP.List

FTP_ListCompleted always returns Success = False

(FTPConnectionClosedException) org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.

I've tryed with different servers and different connection and I can correctly download specific files or send ftp commands.
 
Upvote 0
Code: Copy
Dim FTP1 as FTP
FTP1.Initialize("FTP1", "ftp.xxxxx.com", 21, "xxxxuser", "xxxxpassword")
FTP1.List("/folder/")


Sub FTP1_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
    Log(ServerPath)
    If Success = False Then
   Log("List error")
        Log(LastException)
    Else
        ....... (never get here)
    End If
End Sub


And I've tryed with emulators and different real devices
 
Upvote 0
I use the FTP all the time and it works as it should, however, it does not work on an emulator. It also has issues some times on a data connection on a phone depending on the carrier's setup. Test it on a real device and with WiFi first. Also, log into the FTP with a PC and see what is showing in the default directory because the folder directory may not be there in the default login location.
 
Upvote 0
I use the FTP all the time and it works as it should, however, it does not work on an emulator. It also has issues some times on a data connection on a phone depending on the carrier's setup. Test it on a real device and with WiFi first. Also, log into the FTP with a PC and see what is showing in the default directory because the folder directory may not be there in the default login location.

Of course it was my problem...
First of all, as you said, it doesn't work on the emulator.
Then I had problems with the Wifi Router, but now it's ok.
And with my phone data connection I can't connect (probably carrier limitation).
Anyway I can use Wifi now. Thanks.
Another thing I noticed is that my ftp server disconnects after few seconds of inactivity and I have to initialize connection again. Is it better to do FTP.Close before reconnecting or does not matter ?
 
Upvote 0
Back
Top