protocols - Samba connection with java -
hi have created test program connect samba protocol. motive create test.txt file on shared location string path="smb://192.168.143.134/rtf2xml/"+sharedfolder+"/test.txt";
but when try run program (below code sample)
import java.io.ioexception; import jcifs.smb.ntlmpasswordauthentication; import jcifs.smb.smbfile; import jcifs.smb.smbfileoutputstream; public class test { /** * @param args * @throws ioexception */ public static void main(string[] args) throws ioexception { string user = "abc"; string pass ="123456"; string sharedfolder="input"; string path="smb://192.168.143.134/rtf2xml/"+sharedfolder+"/test.txt"; ntlmpasswordauthentication auth = new ntlmpasswordauthentication("192.168.143.134",user, pass); smbfile smbfile = new smbfile(path, auth); smbfile.createnewfile(); smbfileoutputstream smbfos = new smbfileoutputstream(smbfile); smbfos.write("testing....and writing file".getbytes()); system.out.println("completed ...nice !"); } }
it throwing exception
exception in thread "main" jcifs.smb.smbexception: failed negotiate jcifs.smb.smbexception: timeout trying open socket java.net.connectexception: connection refused: connect @ java.net.dualstackplainsocketimpl.connect0(native method) @ java.net.dualstackplainsocketimpl.socketconnect(unknown source) @ java.net.abstractplainsocketimpl.doconnect(unknown source) @ java.net.abstractplainsocketimpl.connecttoaddress(unknown source) @ java.net.abstractplainsocketimpl.connect(unknown source) @ java.net.plainsocketimpl.connect(unknown source) @ java.net.sockssocketimpl.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.<init>(unknown source) @ java.net.socket.<init>(unknown source) @ jcifs.netbios.nbtsocket.<init>(nbtsocket.java:59) @ jcifs.smb.smbtransport.run(smbtransport.java:342) @ java.lang.thread.run(unknown source) @ jcifs.smb.smbtransport.start(smbtransport.java:315) @ jcifs.smb.smbtransport.negotiate0(smbtransport.java:865) @ jcifs.smb.smbtransport.negotiate(smbtransport.java:941) @ jcifs.smb.smbtree.treeconnect(smbtree.java:119) @ jcifs.smb.smbfile.connect(smbfile.java:827) @ jcifs.smb.smbfile.connect0(smbfile.java:797) @ jcifs.smb.smbfile.open0(smbfile.java:852) @ jcifs.smb.smbfile.createnewfile(smbfile.java:2265) @ test.main(test.java:22) @ jcifs.smb.smbtransport.negotiate(smbtransport.java:947) @ jcifs.smb.smbtree.treeconnect(smbtree.java:119) @ jcifs.smb.smbfile.connect(smbfile.java:827) @ jcifs.smb.smbfile.connect0(smbfile.java:797) @ jcifs.smb.smbfile.open0(smbfile.java:852) @ jcifs.smb.smbfile.createnewfile(smbfile.java:2265) @ test.main(test.java:22)
how rid of this?
but l think have make sure destination server(192.168.143.134) , alive.
you can write following way, since ip in included in smb link.
public static void main(string[] args) throws ioexception { string user = "abc"; string pass ="123456"; string sharedfolder="input"; string path="smb://192.168.143.134/rtf2xml/"+sharedfolder+"/test.txt"; ntlmpasswordauthentication auth = new ntlmpasswordauthentication("",user, pass);//note here smbfile smbfile = new smbfile(path, auth); smbfile.createnewfile(); smbfileoutputstream smbfos = new smbfileoutputstream(smbfile); smbfos.write("testing....and writing file".getbytes()); system.out.println("completed ...nice !");
} ....
Comments
Post a Comment