public void close() throws IOException { state = 0; if (out != null) out.close(); } }
public void close() throws IOException { state = 0; if (out != null) out.close(); } }
public void close() throws IOException { state = 0; if (out != null) out.close(); } }
public void close() throws IOException { state = 0; if (out != null) out.close(); } }
SmbFile destFile = new SmbFile("smb://host/SharedFiles/adoc.doc", auth); SmbFileOutputStream sfos = new SmbFileOutputStream(destFile); poifs.writeFilesystem(sfos); sfos.close();
SmbFile originalFile = new SmbFile(filePath + fi.getName()); InputStream in; in = fi.getInputStream(); //fi is FileItem SmbFileOutputStream out; out = new SmbFileOutputStream(originalFile); IOUtils.copy(in, out); in.close(); out.close();
SmbFile remoteFile = new SmbFile(remotePath, auth); SmbFileOutputStream out = new SmbFileOutputStream(remoteFile); FileInputStream fis = new FileInputStream(localFile); out.write(IOUtils.toByteArray(fis)); out.close();
String user = "user:password"; NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user); String path = "smb://my_machine_name/D/MyDev/test.txt"; SmbFile sFile = new SmbFile(path, auth); SmbFileOutputStream sfos = new SmbFileOutputStream(sFile); sfos.write("Test".getBytes()); sfos.close();
Date now = new Date(); String strDateFormat = "EEEE, MMMM dd, yyyy HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); String txtVal = "INFO\t" + usr + "\t" + sdf.format(now) + "\t" +count +"\t"+"Ver.1"; NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("XXXX", "XXXXX", "XXXXXX"); String path = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; SmbFile sFile = new SmbFile(path, auth); //SmbFileOutputStream sfos = new SmbFileOutputStream(sFile); SmbFileOutputStream sfos = new SmbFileOutputStream(sFile, true); sfos.write((txtVal+"\r\n").getBytes()); sfos.close();
// local source file and target smb file File fileSource = new File("C:/example.jpg"); SmbFile smbFileTarget = new SmbFile(smbFileContext, "example.jpg"); // input and output stream FileInputStream fis = new FileInputStream(fileSource); SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFileTarget); // writing data try { // 16 kb final byte[] b = new byte[16*1024]; int read = 0; while ((read=fis.read(b, 0, b.length)) > 0) { smbfos.write(b, 0, read); } } finally { fis.close(); smbfos.close(); }
try { String filePath = "myserver/dir"; String fileName = "myFile.txt"; String user = "username"; String password = "password"; // URL: smb://user:passwd@host/share/filname SmbFileOutputStream out = new SmbFileOutputStream("smb://" + user + ":" + password + "@" + filePath + File.separator + fileName); out.write("test".getBytes()); out.close(); } catch (Exception e) { e.printStackTrace(); }
static final String USER_NAME = "Username"; static final String PASSWORD = "Password"; static final String DOMAIN = "XYZ"; static final String NETWORK_FOLDER = "smb://ip-address/Folder-Path/"; try{ String fileContent = "This is a test file"; String fileName = "test_File.txt" NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(DOMAIN,USER_NAME, PASSWORD); String path = NETWORK_FOLDER + fileName; System.out.println("Path: " +path); SmbFile sFile = new SmbFile(path, auth); SmbFileOutputStream sfos = new SmbFileOutputStrea(sFile); sfos.close(); sfos.write(fileContent.getBytes()); }catch (Exception e) { e.printStackTrace(); }
} finally { try { sfos.close(); is.close(); } catch (Exception e) {
/** * Copy file to smb share. * * @param sourceFile the source file * @param destinationFile the destination file * @param domain the domain * @param domainUsername the domain username * @param domainPassword the domain password * @implNote |copyFileToSMBShare;|c:\test.xml|smb://Server/folder/copied.xml|domain|username|password| */ public void copyFileToSMBShare(String sourceFile, String destinationFile, String domain, String domainUsername, String domainPassword) { Path source = Paths.get(sourceFile); if (!destinationFile.startsWith("smb:")) { destinationFile = "smb:" + destinationFile; } try { NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, domainUsername, domainPassword); SmbFile sFile = new SmbFile(destinationFile, auth); SmbFileOutputStream sfos = new SmbFileOutputStream(sFile); Files.copy(source, sfos); sfos.close(); } catch (IOException e) { throw new CommandException("Something went wrong copying the file " + e.getMessage()); } }
sfos.close();