SmbFile remoteFile;//<-- HERE try { OutputStream os = new FileOutputStream(DestinationFile); InputStream is = null; is = remoteFile.getInputStream();
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(credentials); SmbFile remoteFile = new SmbFile (sourceFile, auth); InputStream inputStreamFromLan = remoteFile.getInputStream(); OutputStream outputStreamToLocal = new FileOutputStream(outputFile); int bufferSize = 5096; byte[] b = new byte[bufferSize]; int noOfBytes = 0; while( (noOfBytes = inputStreamFromLan.read(b)) != -1 ) { outputStreamToLocal.write(b, 0, noOfBytes); } outputStreamToLocal.close(); inputStreamFromLan.close();
public InputStream read(String file) throws IOException { return $(file).getInputStream(); }
public InputStream read(String file) throws IOException { return $(file).getInputStream(); }
try { SmbFile source = new SmbFile("smb://username:password@a.b.c.d/sandbox/sambatosdcard.txt"); File destination = new File(Environment.DIRECTORY_DOWNLOADS, "SambaCopy.txt"); InputStream in = source.getInputStream(); OutputStream out = new FileOutputStream(destination); // Copy the bits from Instream to Outstream byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // Maybe in.close(); out.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain", "username", "password"); SmbFile smbFile = new SmbFile("//path", auth); InputStream in; if (smbFile.exists()) { in = smbFile.getInputStream(); }
private int readSmbFile(SmbFile f) throws IOException { InputStream in=null; try { in = f.getInputStream(); return Integer.parseInt(IOUtils.toString(in)); } finally { IOUtils.closeQuietly(in); } }
private int readSmbFile(SmbFile f) throws IOException { InputStream in=null; try { in = f.getInputStream(); return Integer.parseInt(IOUtils.toString(in)); } finally { IOUtils.closeQuietly(in); } }
String source = "smb://SERVER/PATH/FILE"; NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "USERNAME", "PASSWORD"); SmbFile sourceFile = new SmbFile(source, auth); String destination = "LOCAL_PATH_TO_FILE"; byte[] buffer; int length; try { FileOutputStream fileOutputStream = new FileOutputStream(destination); InputStream fileInputStream = sourceFile.getInputStream(); try { buffer = new byte[16 * 1024 * 1024]; while ((length = fileInputStream.read(buffer)) > 0) { fileOutputStream.write(buffer, 0, length); } } finally { fileInputStream.close(); fileOutputStream.close(); } } catch (SmbException e) { // Error handling. } catch (FileNotFoundException e) { // Error handling. } catch (IOException e) { // Error handling. }
import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.junit.Test; import jcifs.smb.SmbFile; import junit.framework.TestCase; public class JCifstest extends TestCase { @Test public void testJCifs() throws IOException { System.out.println(Charset.defaultCharset()); SmbFile smbFile = new SmbFile("smb://myuser:mypass@myserver/basepath/人事部要員・コスト管理課/test.txt"); File destFile = new File("/tmp/" + smbFile.getName()); FileUtils.writeByteArrayToFile(destFile, IOUtils.toByteArray(smbFile.getInputStream())); assertEquals("content", FileUtils.readFileToString(destFile)); } }
private String copyFileToHDFS(FileSystem hdfs, String smbSourceFile, Path dest, NtlmPasswordAuthentication auth) throws IOException { SmbFile smbFile = new SmbFile(smbSourceFile, auth); String name = smbFile.getName(); Path destFile = new Path(dest, name); LOG.debug("Thread {} is copying source file {}, dest file {}", Thread.currentThread().getName(), smbFile.getName(), destFile.getName()); // If file already exists, then we skip over. if (hdfs.exists(destFile) && !config.overwrite) { LOG.info("File {} already exists on HDFS, Skipping", destFile.getName()); return null; } LOG.info("Copying file {} to {}", smbSourceFile, destFile.toString()); try (InputStream in = smbFile.getInputStream(); BufferedOutputStream out = new BufferedOutputStream(hdfs.create(destFile), config.bufferSize)) { ByteStreams.copy(in, out); } catch (IOException e) { LOG.warn("Exception in copying the file {}", name, e); } return name; }
public InputStream getFile(String path) throws IOException { SmbFile smbFile = new SmbFile(encodeForSmb(path), authentication); return smbFile.getInputStream(); }
public InputStream getFile(String path) throws IOException { SmbFile smbFile = new SmbFile(encodeForSmb(path), authentication); return smbFile.getInputStream(); }
@Override public InputStream readRaw(String source) throws IOException { SmbFile remoteFile = createSmbFileObject(source); if (!remoteFile.isFile()) { throw new NestedIOException("Resource [" + source + "] is not a file."); } return remoteFile.getInputStream(); }
InputStream in = f.getInputStream(); while (in.read(buf) > 0) {
InputStream in = f.getInputStream(); while (in.read(buf) > 0) {
InputStream in = f.getInputStream(); while (in.read(buf) > 0) {
InputStream in = f.getInputStream(); while (in.read(buf) > 0) {
/** * Reads the remote resource specified by path and copies its contents to the specified * {@link OutputStream}. * @param _path path to a remote file * @param _outputStream output stream * @throws IOException on error conditions returned by a CIFS server or if the remote resource is not a file. */ @Override public void read(String _path, OutputStream _outputStream) throws IOException { Assert.hasText(_path, "path must not be empty"); Assert.notNull(_outputStream, "outputStream must not be null"); try { SmbFile remoteFile = createSmbFileObject(_path); if (!remoteFile.isFile()) { throw new NestedIOException("Resource [" + _path + "] is not a file."); } FileCopyUtils.copy(remoteFile.getInputStream(), _outputStream); } catch (SmbException _ex) { throw new NestedIOException("Failed to read resource [" + _path + "].", _ex); } if (logger.isInfoEnabled()) { logger.info("Successfully read resource [" + _path + "]."); } }
public Endpoint attach(PresentationSyntax syntax) throws IOException { if (attached) throw new RpcException("Transport already attached."); //with the first flag an access denied exception occurs //with the second one file not found. so changing code here. /*pipe = new SmbNamedPipe(address, (0x2019f << 16) | SmbNamedPipe.PIPE_TYPE_RDWR | SmbNamedPipe.PIPE_TYPE_DCE_TRANSACT); * */ pipe = new SmbNamedPipe(address, SmbNamedPipe.PIPE_TYPE_DCE_TRANSACT); in2 = pipe.getInputStream(); out = pipe.getNamedPipeOutputStream(); in = pipe.getNamedPipeInputStream(); attached = true; return new ConnectionOrientedEndpoint(this, syntax); }