Reputation: 153
I want to save a message in a text file on an android phone onto a hosted web server like bluehost of which I have a username and password. I want to store the file in an arbitrary directory on the server.
What are the general strategies that this could be accomplished? I want to use the HTTP protocol, is that a good idea? Is there a better way?
Upvotes: 0
Views: 179
Reputation: 153872
Transmit a file from an android phone to hosted web space
You import the JSCH jars into your Android application, then you load up the JSCH manager classes and use the defined functions to transmit or receive files between an android phone and hosted webspace.
Run a command over SSH with JSch
JSCH has FTP functionality where you can transmit from phone to hosted web space and will work as long as the hosted web space is reachable by the phone. You can also do the same thing in reverse.
Upvotes: 0
Reputation: 3241
You can try to POST that string to the server:
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.example.com");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("yourVarName", stringVar);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
return (response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 204);
} catch (ClientProtocolException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
Upvotes: 1