String user = "your_user_name"; String pass ="your_pass_word"; String sharedFolder="shared"; String path="smb://ip_address/"+sharedFolder+"/test.txt"; NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass); SmbFile smbFile = new SmbFile(path,auth); SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile); smbfos.write("testing....and writing to a file".getBytes()); System.out.println("completed ...nice !");
protected void doSendFragment(byte[] buf, int off, int length, boolean isDirect) throws IOException { if (out != null && out.isOpen() == false) throw new IOException("DCERPC pipe is no longer open"); if (in == null) in = (SmbFileInputStream)pipe.getNamedPipeInputStream(); if (out == null) out = (SmbFileOutputStream)pipe.getNamedPipeOutputStream(); if (isDirect) { out.writeDirect( buf, off, length, 1 ); return; } out.write(buf, off, length); } protected void doReceiveFragment(byte[] buf, boolean isDirect) throws IOException {
/** * Writes b.length bytes from the specified byte array to this * file output stream. * * @throws IOException if a network error occurs */ public void write( byte[] b ) throws IOException { write( b, 0, b.length ); }
/** * Writes the specified byte to this file output stream. * * @throws IOException if a network error occurs */ public void write( int b ) throws IOException { tmp[0] = (byte)b; write( tmp, 0, 1 ); }
/** * Writes b.length bytes from the specified byte array to this * file output stream. * * @throws IOException if a network error occurs */ public void write( byte[] b ) throws IOException { write( b, 0, b.length ); }
/** * Writes b.length bytes from the specified byte array to this * file output stream. * * @throws IOException * if a network error occurs */ @Override public void write ( byte[] b ) throws IOException { write(b, 0, b.length); }
/** * Writes the specified byte to this file output stream. * * @throws IOException if a network error occurs */ public void write( int b ) throws IOException { tmp[0] = (byte)b; write( tmp, 0, 1 ); }
/** * Writes b.length bytes from the specified byte array to this * file output stream. * * @throws IOException * if a network error occurs */ @Override public void write ( byte[] b ) throws IOException { write(b, 0, b.length); }
/** * Writes b.length bytes from the specified byte array to this * file output stream. * * @throws IOException if a network error occurs */ public void write( byte[] b ) throws IOException { write( b, 0, b.length ); }
/** * Writes the specified byte to this file output stream. * * @throws IOException * if a network error occurs */ @Override public void write ( int b ) throws IOException { this.tmp[ 0 ] = (byte) b; write(this.tmp, 0, 1); }
/** * Writes the specified byte to this file output stream. * * @throws IOException * if a network error occurs */ @Override public void write ( int b ) throws IOException { this.tmp[ 0 ] = (byte) b; write(this.tmp, 0, 1); }
/** * Writes the specified byte to this file output stream. * * @throws IOException if a network error occurs */ public void write( int b ) throws IOException { tmp[0] = (byte)b; write( tmp, 0, 1 ); }
/** * Writes b.length bytes from the specified byte array to this * file output stream. * * @throws IOException if a network error occurs */ public void write( byte[] b ) throws IOException { write( b, 0, b.length ); }
/** * Writes the specified byte to this file output stream. * * @throws IOException if a network error occurs */ public void write( int b ) throws IOException { tmp[0] = (byte)b; write( tmp, 0, 1 ); }
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", username, password); sharepath = "smb://" + pathtosharefolder + test.txt; sFile = new SmbFile(sharepath, auth); SmbFileOutputStream out = new SmbFileOutputStream(file, true); out.write(text.getBytes());
SmbFile remoteFile = new SmbFile(remotePath, auth); SmbFileOutputStream out = new SmbFileOutputStream(remoteFile); FileInputStream fis = new FileInputStream(localFile); out.write(IOUtils.toByteArray(fis)); out.close();
import jcifs.smb.NtlmPasswordAuthentication; import jcifs.smb.SmbFile; import jcifs.smb.SmbFileOutputStream; public class Logon { public static void main( String argv[] ) throws Exception { 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("Muneeb Ahmad".getBytes()); System.out.println("Done"); } }
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();
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(); }