- mSchemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));\r
- }\r
- \r
- public boolean downloadFile(String filepath, File targetPath) {\r
- HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ", "%20"));\r
- get.setHeader("Host", mUri.getHost());\r
- get.setHeader("User-Agent", "Android-ownCloud");\r
- \r
- try {\r
- HttpResponse response = mHttpClient.execute(mTargetHost, get, mHttpContext);\r
- if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {\r
- return false;\r
- }\r
- BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent());\r
- FileOutputStream fos = new FileOutputStream(targetPath);\r
- \r
- byte[] bytes = new byte[512];\r
- int readResult;\r
- while ((readResult = bis.read(bytes)) != -1) fos.write(bytes, 0, readResult);\r
- \r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- return false;\r
- }\r
- return true;\r
- }\r
- \r
- void getFileList(String dirPath) {\r
- \r
- }\r
+ Protocol.registerProtocol("https", new Protocol("https", new EasySSLSocketFactory(), 443));
+ }
+
+ public boolean downloadFile(String filepath, File targetPath) {
+ //HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ", "%20"));\r
+ \r
+ Log.e("ASD", mUri.toString() + URLDecoder.decode(filepath) + "");\r
+ GetMethod get = new GetMethod(mUri.toString() + URLDecoder.decode(filepath));\r
+
+// get.setHeader("Host", mUri.getHost());
+// get.setHeader("User-Agent", "Android-ownCloud");
+
+ try {
+ int status = executeMethod(get);
+ if (status != HttpStatus.SC_OK) {
+ return false;
+ }
+ BufferedInputStream bis = new BufferedInputStream(get.getResponseBodyAsStream());
+ FileOutputStream fos = new FileOutputStream(targetPath);
+
+ byte[] bytes = new byte[512];
+ int readResult;
+ while ((readResult = bis.read(bytes)) != -1) fos.write(bytes, 0, readResult);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ public boolean putFile(String localFile,
+ String remoteTarget,
+ String contentType) {
+ boolean result = true;
+
+ try {
+ FileRequestEntity entity = new FileRequestEntity(new File(localFile), contentType);\r
+ PutMethod put = new PutMethod(mUri.toString() + remoteTarget.substring(1));\r
+ put.setRequestEntity(entity);\r
+ int status = executeMethod(put);\r
+ Log.d(TAG, "PUT method return with status "+status);
+
+ Log.i(TAG, "Uploading, done");
+ } catch (final Exception e) {
+ Log.i(TAG, ""+e.getMessage());
+ result = false;
+ }
+
+ return result;
+ }