jcifs upload in Kotlin

42 views Asked by At

I am trying to code an app that uploads an image to SMB share folder.

however i have errors with login, but the credentials and smb server path are correct.

this is the code:

 private fun uploadImageToSMB(filePath: String) {
        val auth = NtlmPasswordAuthentication(null, USERNAME, PASSWORD)
        val file = File(filePath)
        val fileName = file.name
        val smbFile = SmbFile(SERVER_PATH + fileName, auth)

        try {
            val inputStream = file.inputStream()
            val outputStream = smbFile.outputStream

            inputStream.copyTo(outputStream)

            outputStream.close()
            inputStream.close()

            Log.d(TAG, "File uploaded successfully")
        } catch (e: Exception) {
            e.printStackTrace()
            Log.e(TAG, "File upload failed: ${e.message}")
        }
    }
}

I get error that it could not log in.

0

There are 0 answers