java


Why is my java class not connecting to remote drive using smb (When correct username and password is used)? [duplicate]


I have a question about accessing file with Samba JCIFS.
So there is a server I want to access, let's call it server.unv.edu and the workgroup is WKGRP.
there is a share in this server: \\server.unv.edu\pcb$
the way I am trying to access to the server is :
public class SMBAuthenticator extends NtlmAuthenticator{
private String username = "username";
private String password = "password";
private String domain = "smb://server.unv.edu/WKGRP/";
public SMBAuthenticator(){
NtlmAuthenticator.setDefault(this);
}
and
public class SMBConnection{
public String urlString = "smb://server.unv.edu/pcb$/path/file.txt";
NtlmPasswordAuthentication auth;
SmbFile smbFile;
public SMBConnection() throws MalformedURLException{;
//url = new URL(urlString);
SMBAuthenticator authenticator = new SMBAuthenticator();
auth = authenticator.getNtlmPasswordAuthentication();
smbFile = new SmbFile(urlString, auth);
}
public InputStream getSMBInputStream() throws IOException{
return this.smbFile.getInputStream();
}
public InputStream getInputStream() throws IOException{
InputStream is = this.getSMBInputStream();
return is;
}
}
but this doesnt work.and I got an error of
jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:544)
at jcifs.smb.SmbTransport.send(SmbTransport.java:661)
at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:390)
at jcifs.smb.SmbSession.send(SmbSession.java:218)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:176)
at jcifs.smb.SmbFile.doConnect(SmbFile.java:929)
at jcifs.smb.SmbFile.connect(SmbFile.java:954)
at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
at jcifs.smb.SmbFile.open0(SmbFile.java:972)
at jcifs.smb.SmbFile.open(SmbFile.java:1006)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
at jcifs.smb.SmbFile.getInputStream(SmbFile.java:2844)
at edu.umd.lib.sambaConnection.SMBConnection.getSMBInputStream(SMBConnection.java:33)
at edu.umd.lib.sambaConnection.SMBConnection.getInputStream(SMBConnection.java:37)
at edu.umd.lib.sambaConnection.SambaConnectionTest.test(SambaConnectionTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Can Anyone give me a suggestion or a correctness of my code, to help me access to the file?
Thank you so much.
You are making this harder than it should be. Please follow the below steps and make sure the shared folder you are creating has write access for this user you are using.
download the jar file http://jcifs.samba.org/ (there is only one jar file)
copy and paste the below code with your information for user name, password and shared folder and that's all you need
I was running this on Linux and wanted to write to a Windows box so you want to create a shared folder and put the shared folder name in the below variable
if you don't know how to create shared folder on windows ...use google as always
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 !");

Related Links

Need to schedule jobs for the script to be run at aspecific time
Clicking my JButton but not getting the action shown before i click another button in my JFrame using ActionListener?
Convert date in proper format in android
Parse Text file in Java
Open a file using Desktop(java.awt)
Search optimization using Apache Lucene
What will happen if I upload a large file in larger chunks i.e. greater then 1024 bytes?
Spring Social-Java application for accessing LinkedIn data
How to find out the odd integers in an array using a recursive method?
Issue while executing buildscript for generating war for GWTP project
SAX Parse exception while parsing google calendar
Regarding REST Path Conflict
ANTLR4 throws java.lang.StackOverflowError on longer files
Can I change the maxActive property of a org.apache.tomcat.jdbc.pool.DataSource dynamically?
TreeSet not sorting properly
What is the runtime when using a List or Array as your key in a Hashmap

Categories

HOME
maven
pandas
vbscript
keycloak
minimum-spanning-tree
c#-4.0
tizen
plot
react-virtualized
iterator
fme
framework7
elm
spring-jdbc
amazon-ecs
graphql
indesign
swagger-ui
portia
synchronization
windows-10-universal
metatrader4
reveal.js
offline
dax
google-apps-marketplace
google-cloud-ml
apache-cayenne
orchardcms
ups
decomposition
seaborn
pugjs
reverse-proxy
cx-freeze
arabic
sox
blazemeter
dxf
user-interaction
spring-mybatis
strncpy
compatibility
jaxb2
c++-amp
microsoft-chart-controls
sql-server-2012-express
preg-match
uisplitview
data-manipulation
create-table
siesta-swift
google-sites-2016
scorm2004
kendo-ui-grid
webtest
uiswipegesturerecognizer
form-data
rotational-matrices
mmenu
sequential
picasso
http-digest
scaffold
unobtrusive-validation
dism
avro4s
pdf-reactor
unixodbc
gpx
sencha-touch-2.3
segment
convertapi
scorm
dotcover
rails-routing
tizen-native-app
nativeapplication
np-complete
windows-mobile-6.5
ifs
memory-alignment
nbconvert
smart-table
topbeat
libpng
multi-level
gridview-sorting
nsviewcontroller
react-native-listview
prettytensor
hill-climbing
ready-api
qgraphicsview
pervasive-sql
icu4j
fouc
clipperlib
gadt
titanium-modules
heisenbug
phpthumb
resty-gwt
concurrent-collections
intentservice
ivyde
soundtouch
gwt-rpc
jquery-mobile-dialog
seed
ember-app-kit
tinn-r
sublist
frameset
twrequest
osql
pendrive
gamma
ncqrs
sef
iweb
ajax-forms

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App