+ /**\r
+ * Creates or update a file in the remote server with the contents of a local file.\r
+ * \r
+ * \r
+ * @param localFile Path to the local file to upload.\r
+ * @param remoteTarget Remote path to the file to create or update, URL DECODED\r
+ * @param contentType MIME type of the file.\r
+ * @return 'True' then the upload was successfully completed\r
+ */\r
+ public boolean putFile(String localFile, String remoteTarget,\r
+ String contentType) {\r
+ boolean result = true;\r
+\r
+ try {\r
+ Log.e("ASD", contentType + "");\r
+ File f = new File(localFile);\r
+ FileRequestEntity entity = new FileRequestEntity(f, contentType);\r
+ entity.setOnDatatransferProgressListener(mDataTransferListener);\r
+ Log.e("ASD", f.exists() + " " + entity.getContentLength());\r
+ PutMethod put = new PutMethod(mUri.toString() + WebdavUtils.encodePath(remoteTarget));\r
+ put.setRequestEntity(entity);\r
+ Log.d(TAG, "" + put.getURI().toString());\r
+ int status = executeMethod(put, 0);\r
+ Log.d(TAG, "PUT method return with status " + status);\r
+\r
+ Log.i(TAG, "Uploading, done");\r
+ } catch (final Exception e) {\r
+ Log.i(TAG, "" + e.getMessage());\r
+ result = false;\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Tries to log in to the given WedDavURI, with the given credentials\r
+ * @param uri To test\r
+ * @param username Username to check\r
+ * @param password Password to verify\r
+ * @return A {@link HttpStatus}-Code of the result. SC_OK is good.\r
+ */\r
+ public static int tryToLogin(Uri uri, String username, String password) {\r
+ int returnCode = 0;\r
+ WebdavClient client = new WebdavClient();\r
+ client.setCredentials(username, password);\r
+ HeadMethod head = new HeadMethod(uri.toString());\r
+ try {\r
+ returnCode = client.executeMethod(head);\r
+ } catch (Exception e) {\r
+ Log.e(TAG, "Error: " + e.getMessage());\r
+ }\r
+ return returnCode;\r
+ }\r
+\r
+ /**\r
+ * Creates a remote directory with the received path.\r
+ * \r
+ * @param path Path of the directory to create, URL DECODED\r
+ * @return 'True' when the directory is successfully created\r
+ */\r
+ public boolean createDirectory(String path) {\r
+ try {\r
+ MkColMethod mkcol = new MkColMethod(mUri.toString() + WebdavUtils.encodePath(path));\r
+ int status = executeMethod(mkcol);\r
+ Log.d(TAG, "Status returned " + status);\r
+ Log.d(TAG, "uri: " + mkcol.getURI().toString());\r
+ Log.i(TAG, "Creating dir completed");\r
+ } catch (final Exception e) {\r
+ e.printStackTrace();\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+\r
+\r
+ /**\r
+ * Requests the received method with the received timeout (milliseconds).\r
+ * \r
+ * Executes the method through the inherited HttpClient.executedMethod(method).\r
+ * \r
+ * Sets the socket timeout for the HttpMethodBase method received.\r
+ * \r
+ * @param method HTTP method request.\r
+ * @param timeout Timeout to set, in milliseconds; <= 0 means infinite.\r
+ */\r
+ public int executeMethod(HttpMethodBase method, int readTimeout) throws HttpException, IOException {\r
+ int oldSoTimeout = getParams().getSoTimeout();\r
+ try {\r
+ if (readTimeout < 0) { \r
+ readTimeout = 0;\r
+ }\r
+ HttpMethodParams params = method.getParams();\r
+ params.setSoTimeout(readTimeout); \r
+ method.setParams(params); // this should be enough...\r
+ getParams().setSoTimeout(readTimeout); // ... but this is necessary for HTTPS\r
+ return executeMethod(method);\r
+ } finally {\r
+ getParams().setSoTimeout(oldSoTimeout);\r
+ }\r
+ }\r