Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. import jcifs.smb.NtlmPasswordAuthentication;
  2. import jcifs.smb.SmbFile;
  3. import jcifs.smb.SmbFileOutputStream;
  4.  
  5.    private class MyCopy extends AsyncTask<String, String, String> {
  6.  
  7.         String z = "";
  8.         String username = "", password = "", servername = "", filestocopy = "";
  9.  
  10.         @Override
  11.         protected void onPreExecute() {
  12.  
  13.             String Counting = count.getText().toString().trim();
  14.             String picfilename = cardnumberbox.getText().toString().trim();
  15.             {
  16.                 if (picfilename.substring(0, 1).startsWith("K")) {
  17.                     picfilename = Counting + picfilename.substring(1);
  18.                 } else {
  19.                     picfilename = Counting + picfilename;//.substring(0));
  20.                 }
  21.             }
  22.  
  23.             username = setingPreferences.getString("smbuser","");
  24.             password = setingPreferences.getString("smbpass", "");
  25.             servername = "smb://"+setingPreferences.getString("smppath","");
  26.             filestocopy = setingPreferences.getString("copyfrom","") + picfilename + ".jpg";
  27.         }
  28.  
  29.         @Override
  30.         protected void onPostExecute(String r) {
  31.             Toast.makeText(CameraActivity.this, r, Toast.LENGTH_SHORT).show();
  32.         }
  33.  
  34.         @Override
  35.        protected String doInBackground(String... params) {
  36.                       File file = new File(filestocopy);
  37.                   String filename = file.getName();
  38.                 NtlmPasswordAuthentication auth1 = new NtlmPasswordAuthentication(
  39.                       servername, username, password);
  40.             try {
  41.  
  42.                 SmbFile sfile = new SmbFile(servername + "/" + filename, auth1);
  43.                           if (!sfile.exists())
  44.                             sfile.createNewFile();
  45.                       sfile.connect();
  46.  
  47.                     InputStream in = new FileInputStream(file);
  48.  
  49.                 SmbFileOutputStream sfos = new SmbFileOutputStream(sfile);
  50.                           byte[] buf = new byte[8192];
  51.                         int len;
  52.                       while ((len = in.read(buf)) >= 0) {
  53.                         sfos.write(buf, 0, len);
  54.                   }
  55.                 in.close();
  56.               sfos.close();
  57.                 z = getString(R.string.pic_uploaded);
  58.  
  59.                       } catch (Exception ex) {
  60.             }
  61.  
  62.                 return z;
  63.  
  64.         }
  65.  
  66.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement