daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest May 27th, 2018 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.IOException;
  2. import java.io.InputStream;
  3. import java.io.OutputStream;
  4. import java.net.URI;
  5.  
  6. import org.apache.hadoop.conf.Configuration;
  7. import org.apache.hadoop.fs.FileSystem;
  8. import org.apache.hadoop.fs.Path;
  9. import org.apache.hadoop.io.IOUtils;
  10.  
  11. import jcifs.smb.NtlmPasswordAuthentication;
  12. import jcifs.smb.SmbFile;
  13. import jcifs.smb.SmbFileInputStream;
  14.  
  15. public class FileWriteToHDFS
  16. {
  17.     public static void main(String[] args) throws Exception
  18.     {
  19.         String src = args[0];
  20.         String dest = args[1];
  21.  
  22.         Console console = System.console();
  23.         String username = console.readLine("Username: ");
  24.         String password = new String(console.readPassword("Password: "));
  25.         String domain = console.readLine("Authentication Domain: ");
  26.  
  27.         NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, username, password);
  28.         SmbFile srcSMB = new SmbFile (src, auth);
  29.  
  30.         InputStream in = new SmbFileInputStream(srcSMB);
  31.  
  32.         Configuration myConf = new Configuration();
  33.  
  34.         FileSystem fs = FileSystem.get(URI.create(dest), myConf);
  35.         OutputStream out = fs.create(new Path(dest));
  36.         try
  37.         {
  38.             IOUtils.copyBytes(in, out, 4096, false);
  39.         }
  40.         catch(IOException e)
  41.         {
  42.             e.printStackTrace();
  43.         }
  44.         finally
  45.         {
  46.             IOUtils.closeStream(in);
  47.         }
  48.     }
  49. }
  50.    
  51. scp source_file_name user@/path/file_name
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top