Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.URI;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.io.IOUtils;
- import jcifs.smb.NtlmPasswordAuthentication;
- import jcifs.smb.SmbFile;
- import jcifs.smb.SmbFileInputStream;
- public class FileWriteToHDFS
- {
- public static void main(String[] args) throws Exception
- {
- String src = args[0];
- String dest = args[1];
- Console console = System.console();
- String username = console.readLine("Username: ");
- String password = new String(console.readPassword("Password: "));
- String domain = console.readLine("Authentication Domain: ");
- NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, username, password);
- SmbFile srcSMB = new SmbFile (src, auth);
- InputStream in = new SmbFileInputStream(srcSMB);
- Configuration myConf = new Configuration();
- FileSystem fs = FileSystem.get(URI.create(dest), myConf);
- OutputStream out = fs.create(new Path(dest));
- try
- {
- IOUtils.copyBytes(in, out, 4096, false);
- }
- catch(IOException e)
- {
- e.printStackTrace();
- }
- finally
- {
- IOUtils.closeStream(in);
- }
- }
- }
- scp source_file_name user@/path/file_name
Add Comment
Please, Sign In to add comment