3

I have been working on File Upload in Android and found out both HTTP and FTP are available to do file upload, but HTTP is supported natively by Android , But FTP is through Apache commons library, also found out both has its own pros and cons but not in terms of mobile's perspective, because in mobiles network breaks is very common,

so my questions

1) Should I stick to HTTP multi-part file upload no matter what in mobiles or is it fine to use FTP

2) My Server is FTP storage repository, can I still use HTTP to upload without issue

3) Does FTP use multipart upload just like HTTP or how is network issues handled when there is frequent breaks

Ujju
  • 2,723
  • 3
  • 25
  • 35

3 Answers3

3

1) Should I stick to HTTP multi-part file upload no matter what in mobiles or is it fine to use FTP

Because of the design FTP is a very bad choice in any networks which use private IPv4 addresses - which due to the shortage of IPv4 addresses is the case with probably most mobile networks. While it might work within one network it will not work within another and if you try to combine FTP with SSL to secure the transport it gets even worse.

HTTP and HTTPS instead work usually without problems. With the use of Range requests you also have the ability to download parts of files, which is important when resuming broken downloads or loading only the necessary parts of a document (like parts of an big PDF file). FTP has limited resume capability but not as useful as the HTTP Range request.

As for resuming uploads FTP has the REST (restart) command. But you need to first find out how much data were received at the server so that you know where to restart. HTTP has no builtin resume for uploads. You could use the Content-Range header within POST or PUT requests but your server need to understand how to deal with this header. Or you could spread the upload over multiple requests which again needs special server side code to rebuild the original file at the server.

The overhead for both protocols is about the same and could be ignored for anything but very small files.

2) My Server is FTP storage repository, can I still use HTTP to upload without issue

If your server has no HTTP interface then you cannot use HTTP. But just the description of "FTP storage repository" does not give enough information about the ways it can be accessed.

3) Does FTP use multipart upload just like HTTP or how is network issues handled when there is frequent breaks

If its broken you need to find out where to restart with the upload (check remote length) and then use REST command.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • Thanks for detailed explaination, clears most of my doubt,,will have a look into server Interface – Ujju Mar 01 '16 at 14:08
  • created http interface,earlier there was just 2 param authentication for the FTP storage – Ujju Mar 08 '16 at 09:52
2

Wrong question. The client OS doesn't matter, and shouldn't be what determines your technology. There's libraries for either. There's advantages to both, pick the one that's appropriate for your use case. That's possibly what you should have asked.

As for question 2- no. FTP and HTTP are different protocols. You use one of the other. You can generally view FTP in a browser because a browser implements both protocols. Using HTTP to talk to an FTP server just won't work.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • As you know android removed apache client keeping efficiency in mind, and also it does not talk about FTP protocol in any of its document for file upload, so it can be assumed that OS gives preference to which is more reliable for users, as for my use case which is best when der is lot of network issues – Ujju Mar 01 '16 at 12:53
  • @Ujju: "android removed apache client keeping efficiency in mind" -- um, no. Google removed HttpClient because they could not continue maintaining it while keeping binary compatibility. You are welcome to use Apache's independent packaging of their HttpClient library for Android. "it can be assumed that OS gives preference to which is more reliable for users" - I would not make that assumption at all. Google has finite development staff, and Android devices have small ROMs to help keep prices down. As a result, not everything can make it into Android. HTTP is orders of magnitude more popular. – CommonsWare Mar 01 '16 at 12:58
1

It depends on bandwith and reliability that you want ;) so maybe all the smartphone OS have the same answer:

  • FTP use more bandwidth, has more reliable file transfer, requires an FTP server.
  • HTTP can use a little less bandwidth, and can use lesser with its more efficent compression, has a little lesser reliability, requires an HTTP server with a server page implementing the upload logics.

Both of them are available for Android, so your choice depends on evaluating these factors.

Luca C.
  • 11,714
  • 1
  • 86
  • 77
  • Im aware of diff's but like u said bandwidth and reliability is the concern when it comes to mobile,. if FTP seems more reliable based on ur answer, which is not though – Ujju Mar 01 '16 at 12:59
  • I very much doubt that HTTP uses less bandwidth. Do you have a source for this claim? – Steffen Ullrich Mar 01 '16 at 13:30
  • @SteffenUllrich http://stackoverflow.com/questions/717200/comparing-http-and-ftp-for-transferring-files and many others on google – Luca C. Mar 02 '16 at 09:29
  • @Luke: the link you provide is about the time needed until the transfer of the first file starts. It is not about bandwidth. Both FTP and HTTP transfer the data in binary form (contrary to for instance mail) and both don't have much protocol overhead. So they don't really differ a lot in the number of bytes needed to transfer a file. – Steffen Ullrich Mar 02 '16 at 09:33