HTTPUtils or FTP ?

Bill Norris

Active Member
Licensed User
Longtime User
What are the pros and cons of using HTTPUtils vs FTP to download files from the web server?
 

Bill Norris

Active Member
Licensed User
Longtime User
FTP Downloading Multiple Files

If I want to FTP download multiple files, do I simply create an array of the file names and iterate through, like this:

B4X:
for i=0 to 10
FTP.DownloadFile("/somefolder/files/" & filename(i), False, File.DirRootExternal, filename(i))
next

or is there a more efficient way?
 
Upvote 0

Bill Norris

Active Member
Licensed User
Longtime User
RE: Need Help

Cannot seem to "get out of the gate" with this. Here is code:

B4X:
Sub Service_Create
   FTP.Initialize("file_transfers", "ftp://www.myserver.com", 21, "user", "password")
End Sub

sub download_file_click
FTP.DownloadFile("/tablet/database/wine_tablet.db", False, File.DirRootExternal, "wine_tablet.db")
end sub

Sub FTP_DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)
Dim s As String
s = "Downloaded " & Round(TotalDownloaded / 1000) & "KB"
If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
Log(s)
End Sub

Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
If Success=True Then
   File.Copy("File.DirRootExternal","wine_tablet.db","File.DirDefaultExternal","wine_tablet.db")
End If
End Sub

It does not appears as though anything is happening regarding the file download. Nothing is being written to the log in the downloadprogress sub. Also, I'm not sure of the significance of the sub name in the initialize statement. What goes in there, since I am using a button sub to initiate the download, and the downloadprogress and downloadcomplete subs are on their own. I know the server name, user and password are correct.
 
Upvote 0

Bill Norris

Active Member
Licensed User
Longtime User
RE:

Made the changes and still nothing. I notice in the tutorial that in the initialization line, the format of the server name is "ftp.servername.com", rather than "ftp://www.servername.com" -- also, is 21 the correct port or might that need to be changed?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Made the changes and still nothing. I notice in the tutorial that in the initialization line, the format of the server name is "ftp.servername.com", rather than "ftp://www.servername.com" -- also, is 21 the correct port or might that need to be changed?

Yes, you shouldn't place the 'www'.
21 is a default port used by many servers.
Finally, perhaps you should ftp in passive mode
B4X:
FTP.PassiveMode =True
after initializing your ftp object.
 
Upvote 0

Bill Norris

Active Member
Licensed User
Longtime User
RE:

That appears to have resolved the problem. Just wondering if the downloads execute in the background if the app is in use when I send the download_file push message?
 
Upvote 0
Top