Back to project page original-android-cgm.
The source code is released under:
Copyright (c) 2014, John Costik All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * ...
If you think the Android project original-android-cgm listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.ht1.cc.upload; //ww w . j a v a 2 s. c om import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.net.*; import org.apache.commons.net.ftp.FTPClient; import android.content.Context; import android.os.AsyncTask; import android.util.Log; public class UploadHelper extends AsyncTask<String, Integer, Long> { Context context; public UploadHelper(Context context) { this.context = context; } protected Long doInBackground(String... data) { //SO, here is where you're going to want to decide //how and where you want to send the "data.csv" //I send to both azure site (FTP) and a google spreadsheet - between the //two I get pretty close to 100% up-time //FTP Example:: FTPClient ftpClient = new FTPClient(); try { ftpClient.connect(InetAddress.getByName("[YOUR SERVER]")); ftpClient.login("USERNAME", "PASSWORD"); ftpClient.changeWorkingDirectory("DIRECTORY"); if (ftpClient.getReplyString().contains("250")) { ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE); BufferedInputStream buffIn = null; buffIn = new BufferedInputStream(new FileInputStream(new File(context.getFilesDir(), "data.csv"))); ftpClient.enterLocalPassiveMode(); ftpClient.storeFile("data.csv", buffIn); buffIn.close(); ftpClient.logout(); ftpClient.disconnect(); } } catch(Exception ex) { ex.printStackTrace(); } return 1L; } protected void onPostExecute(Long result) { super.onPostExecute(result); Log.i("Uploader", result + " Status: FINISHED"); } }