首页 > 解决方案 > Android Studio 格式化问题中的 CIFS/SMB 网络协议

问题描述

我在 android studio 项目中安装了 jcifs-1.3.19 jar。

我想知道为什么我不断收到“W/System.err:jcifs.smb.SmbAuthException:登录失败:未知用户名或密码错误”的异常。

我已经使用“ES File Explore”成功访问了我公司的 Windows 网络驱动器。我有正确的凭据(登录名和密码)。公司“IT”服务台表示,SMB 路径格式如下:

"静态最终字符串 AUTH_PATH = "smb://" + USER_NAME + ":" + PASSWORD "@engstl1.us.crownlift.net/vol1/PIL_SYNECT_TEST_PLAN/Ready_for_Exectuion/";"

这不起作用。有什么我做错了吗?此代码在 AsyncTask 中执行。

static final String AUTH_PATH = "smb://" + USER_NAME + ":" + PASSWORD + "@engstl1.us.crownlift.net/vol1/PIL_SYNECT_TEST_PLAN/Ready_for_Exectuion/";  // From email
String Path = AUTH_PATH + "testfile.text"; // From email
static final String fileContent = "Here is something in this file";
static boolean successful;

@Override
protected void onPreExecute() {
    Log.i(TAG, "in AsyncTask onPreExecute");   // debug msg
}
 @Override
protected String doInBackground(Void... voids) {

    try{
        Log.i(TAG, "IN AsyncTask in try ---------------------------->:" );   // debug msg
        String user = USER_NAME + ":" + PASSWORD;
        System.out.println("User: " + user);

        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
        //String path = NETWORK_FOLDER + "testfile.txt";
        String path = Path;  // From email
        System.out.println("Path: " + path);
        Log.i(TAG, "IN doInBackground method in try after NtlmPasswordAuthentication ---------------------------->:" + auth);   // debug msg

        SmbFile sFile = new SmbFile(path, auth);
        Log.i(TAG, "IN doInBackground method in try after sFile---------------------------->:" + sFile );   // debug msg
        SmbFileOutputStream sfos = new SmbFileOutputStream(sFile,true);
        Log.i(TAG, "IN doInBackground method in try after sfos---------------------------->:" + sfos );   // debug msg not getting here
        sfos.write(fileContent.getBytes());

        successful = true;
        System.out.println("Successful" + successful);
    } catch (Exception e) {
        successful = false;
        Log.i(TAG, "IN doInBackground method Exception---------------------------->:" );   // debug msg
        e.printStackTrace();

Logcat:
05-30 13:58:32.180 22183-26454/com.example.t0028919.person_in_looptesttool 
I/TomsMessage: IN doInBackground method Exception--------------------------- 
->:
05-30 13:58:32.180 22183-26454/com.example.t0028919.person_in_looptesttool 
W/System.err: jcifs.smb.SmbAuthException: Logon failure: unknown user name 
or bad password.
05-30 13:58:32.180 22183-26454/com.example.t0028919.person_in_looptesttool    
W/System.err:     at 
jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:546)
05-30 13:58:32.180 22183-26454/com.example.t0028919.person_in_looptesttool 
W/System.err:     at jcifs.smb.SmbTransport.send(SmbTransport.java:663)
05-30 13:58:32.180 22183-26454/com.example.t0028919.person_in_looptesttool 
W/System.err:     at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:390)
05-30 13:58:32.180 22183-26454/com.example.t0028919.person_in_looptesttool 
W/System.err:     at jcifs.smb.SmbSession.send(SmbSession.java:218)

标签: androidsmb

解决方案


推荐阅读