Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sdfsadfpublic class UploadFileTask extends AsyncTask<String, Void, Boolean>
- {
- private static final int BUFFER_SIZE = 4096;
- private String host;
- private int port;
- private String username;
- private String password;
- private String destDir;
- private File uploadFile;
- public UploadFileTask(String host, int port, String username, String password, String destDir, File uploadFile) {
- this.host = host;
- this.port = port;
- this.username = username;
- this.password = password;
- this.destDir = destDir;
- this.uploadFile = uploadFile;
- }
- @Override
- protected Boolean doInBackground(String... params) {
- FTPUtility util = new FTPUtility(host, port, username, password);
- try
- {
- util.connect();
- util.uploadFile(uploadFile, destDir);
- FileInputStream inputStream = new FileInputStream(uploadFile);
- byte[] buffer = new byte[BUFFER_SIZE];
- int bytesRead = -1;
- long totalBytesRead = 0;
- int percentCompleted = 0;
- long fileSize = uploadFile.length();
- while ((bytesRead = inputStream.read(buffer)) != -1) {
- util.writeFileBytes(buffer, 0, bytesRead);
- totalBytesRead += bytesRead;
- percentCompleted = (int) (totalBytesRead * 100 / fileSize);
- }
- inputStream.close();
- util.finish();
- return true;
- } catch (Exception ex) {
- Log.e(TAG, "Exception => " + ex);
- return false;
- } finally {
- try {
- util.disconnect();
- } catch (FTPException e) {
- Log.e(TAG, "FTPException => " + e);
- }
- }
- }
- protected void onPostExecute(Boolean result) {
- Log.e(TAG, "File Uploading " + result);
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement