- HttpParams params = new BasicHttpParams();\r
- params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);\r
- params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));\r
- params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);\r
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);\r
-\r
- mHttpContext = new BasicHttpContext();\r
- ClientConnectionManager cm = new ThreadSafeClientConnManager(params, mSchemeRegistry);\r
-\r
- int port = mUri.getPort() == -1 ? \r
- mUri.getScheme().equals("https") ? 443 : 80\r
- : mUri.getPort();\r
+ /**\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 = false;\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
+ if (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT) {\r
+ result = true;\r
+ Log.i(TAG, "Uploading, done");\r
+ }\r
+ \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