写/使用Samba / JCIFS问题上传文件(SmbAuthException:访问被拒绝) [英] Write/upload a file using Samba/JCIFS issue (SmbAuthException: Access is denied)

查看:485
本文介绍了写/使用Samba / JCIFS问题上传文件(SmbAuthException:访问被拒绝)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想写来自Android设备的文件共享文件夹窗口。我使用JCIFS和最新版本的<一个href="http://stackoverflow.com/questions/9389366/how-to-access-share-folder-in-windows-through-android-and-read-files">$c$c其中显示可用的网络股的正常工作。所以,我认为一切都确定了JCIFS和我的局域网,无线网络等。这里是code文件上传(其实我只是想写一个文本SRING到文件):

So i'm trying to write a file from android device to windows shared folder. I'm using latest version of JCIFS and code which displays available network shares works fine. So I assume everything is ok with JCIFS and with my LAN, WiFi etc. Here is the code for file upload (actually I just want to write a text Sring to a File):

    public boolean save2Samba(String text, String fileName) {
        try {

            // My Windows shares doesn't require any login/password
            // String name="login";//my windows username
            // String password="password1";//my windows password

            // sSambaFolder contains a path like MYPC/E/SharedFolderName/
            String url = "smb://" + sSambaFolder.toLowerCase()+fileName;

            SmbFile file = null;
            try {
                // assume ANONYMOUS is my case but there is no description of this in JCIFS API
                NtlmPasswordAuthentication auth = NtlmPasswordAuthentication.ANONYMOUS;
                file = new SmbFile(url, auth);
                android.util.Log.i("TestApp",url);
                // output is like smb://mypc/e/sharedfoldername/file.txt;
                SmbFileOutputStream out = new SmbFileOutputStream(file);
                out.write(text.getBytes());
                out.flush();
                out.close();

            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }

            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

由于URL登录我敢肯定,这是正确的(也是我用code我上面提到的检查URL,并浏览该文件夹的含)。
但问题是我总是得到相同的:

Since the url is logged i'm sure it is correct (also I checked the url using the code I mentioned above and it browses the folder's contain).
But the problem is Im always getting the same:

W/System.err(3214): jcifs.smb.SmbAuthException: Access is denied.

股份没有密码保护的,所以我不需要任何用户名/密码才能访问。我能读/写/删除另一个WinPC文件,也没有授权是必需的。此外,我试图创建WinPC为用户的密码与股票,但结果是一样的。所以,我试了几个版本的NtlmPasswordAut​​hentication的,没有运气:

Shares are not password protected, so I don't need any username/password to get access. I could read/write/delete files from another WinPC and no authorization is required. Also I tried to create a password for user on WinPC with shares but result was the same. So I tried several versions of NtlmPasswordAuthentication with no luck:

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("");
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(":");
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("Administrator:"); //actual username on WinPC with shares
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("Administrator");
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,"Administrator","");
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,"","");

那我顺便说一句做错了,如何才达到我的目标时,有没有身份验证要求才能访问共享文件夹?
我的三星电视是基于Linux,并使用Samba客户端在访问同一个共享文件夹从有没有问题,播放MP3(嗯,是的,它只能读取)。由于我的AOS设备通过无线网络连接(而不是电视是通过以太网连接),我还检查访问共享文件夹中使用笔记本电脑+无线网络,没有发现问题访问我的局域网。
补充:
我想现在执行下面几行:

So what am I doing wrong and how to achive my goal when there is no auth is required to get access to shared folder?
BTW my Samsung TV which is linux based and uses samba client is accessing the same shared folder with no problem and plays MP3 from there (well, yes, it reads only). Since my AOS device is accessing my LAN via WiFi (instead of TV which is connected via Ethernet) I also checked access to shared folder using notebook+WiFi and found no problems.
Added:
I'm trying now to execute following lines:

file = new SmbFile(url, auth);
android.util.Log.i("save2Samba", "file.exists(): " + file.exists());

和得到同样的访问被拒绝。我还没有尝试写入文件...

and getting the same Access denied. I'm not even trying to write file...

推荐答案

OMG!解决方案是如此简单!访问网络,这是不登陆/密码保护,因此不需要任何授权不NtlmPasswordAut​​hentication.ANONYMOUS但它是:

OMG!!! Solution was so simple!!! To access network which is not login/password protected and thus doesn't need any authorization is not NtlmPasswordAuthentication.ANONYMOUS BUT it is:

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, null, null);

该死的不是那么明显!

damn it wasn't that obvious!

这篇关于写/使用Samba / JCIFS问题上传文件(SmbAuthException:访问被拒绝)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆