+ boolean downloadFile(String filepath, File targetPath) {
+ HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ", "%20"));
+ get.setHeader("Host", mUri.getHost());
+ get.setHeader("User-Agent", "Android-ownCloud");
+
+ try {
+ HttpResponse response = mHttpClient.execute(mTargetHost, get, mHttpContext);
+ if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ return false;
+ }
+ InputStreamReader isr = new InputStreamReader(response.getEntity().getContent());
+ FileOutputStream fos = new FileOutputStream(targetPath);
+ int oneByte;
+ while ((oneByte = isr.read()) != -1) fos.write(oneByte);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }