当前位置: 首页 > news >正文

太原做网站的鸣蝉公司搜狐财经峰会直播

太原做网站的鸣蝉公司,搜狐财经峰会直播,wordpress迁移修改域名,深圳建设银行网站Android端使用Samba连接共享文件夹,下载或上传文件的功能实现。如果你是用jcifs工具包,那么你要注意jcifs-ng 和 jcifs 支持的SMB版本区别。 JCIFS-NG的github地址 JCIFS官网地址 这里有关于jciffs、jcifs-codelibs、jcifs-ng、smbj的详细介绍 对比 支…

Android端使用Samba连接共享文件夹,下载或上传文件的功能实现。如果你是用jcifs工具包,那么你要注意jcifs-ng 和 jcifs 支持的SMB版本区别。

JCIFS-NG的github地址
JCIFS官网地址 这里有关于jciffsjcifs-codelibsjcifs-ngsmbj的详细介绍

对比

  • 支持的smb版本
    jcifs:
    仅支持SMB 1.0(CIFS), jcifs 最初是针对 SMB 1.0(CIFS)协议开发的,因此它是对 SMB 1.0 版本的最好支持。
    jcifs-ng 2.1:
    此版本默认启用SMB2支持,并包含一些实验性的SMB3.0支持。
    协商的协议级别现在可以使用jcifs.smb.client.minVersion和jcifs.smb.client.maxVersion进行控制(这会弃用jcifs.smb.client.enableSMB2/jcifs.sm b.client.disableSMB1属性)。默认的最小/最大版本是SMB1到SMB210。
    此版本禁止服务器浏览(即服务器/工作组枚举),并包含有关身份验证的一些突破性API更改。
    jcifs-ng 2.0:
    此版本支持SMB2(2.02协议级别),目前仅在配置了jcifs.smb.client.enableSMB2的情况下宣布支持SMB2,但如果服务器不支持SMB1方言,也可以选择支持SMB2。

  • 开发状态:
    jcifs: jcifs 是最初由 Mike Allen 开发的 Java CIFS 实现,最后一个官方发布版本是 1.3.19,发布于 2007 年。此后,jcifs 进入了维护模式,不再进行主要更新。
    jcifs-ng: jcifs-ng(jcifs-next generation)是基于 jcifs 的一个分支,由 Alexander Böhm 等人开发。它是对 jcifs 的改进和扩展,具有更现代化的代码结构和更多功能。jcifs-ng 目前仍在活跃地开发和维护。

  • 功能和性能:
    jcifs-ng 在功能和性能上进行了改进和优化,相比于原始的 jcifs,它提供了更多的功能和更好的性能。例如,jcifs-ng 支持更多的 SMB 协议特性,并且在速度和稳定性方面进行了改进。

  • API 和使用方式:
    jcifs-ng 在 API 和使用方式上与 jcifs 类似,但可能会有一些差异和改进。因此,如果你已经熟悉 jcifs,那么迁移到 jcifs-ng 应该相对容易。

这里使用的是jcifs-ng 2.1.9

添加依赖

implementation 'eu.agno3.jcifs:jcifs-ng:2.1.9'

代码实现(Kotlin)

package com.xxx.customerimport android.util.Log
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import jcifs.CIFSContext
import jcifs.context.SingletonContext
import jcifs.smb.SmbException
import jcifs.smb.SmbFile
import jcifs.smb.SmbFileInputStream
import jcifs.smb.SmbFileOutputStream
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.io.BufferedInputStream
import java.io.BufferedOutputStream
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.util.Propertiesclass SambaManager {private val SAMBA_SERVER_IP = "your server ip"private val SAMBA_USERNAME = "username"private val SAMBA_PASSWORD = "password"companion object {private const val TAG = "SambaManager"private var mCIFSContext: CIFSContext? = null}/*** 上传文件到共享文件夹指定目录* @param viewLifecycleOwner* @param localFilePathList 待上传的本地文件路径列表* @param remoteFolderPath 要上传到的远端路径,*        如果共享文件夹为shared_folder,则该路径应该包含shared_folder,*        如:shared_folder/ 或 shared_folder/xxx* @param onComplete 任务完成厚的回调*/fun uploadFiles(viewLifecycleOwner: LifecycleOwner,localFilePathList: MutableList<String>,remoteFolderPath: String,onComplete: (Int) -> Unit) {viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {var count = 0val smbContext = getCIFSContext()for (filePath in localFilePathList) {val localFile = File(filePath)if (!localFile.exists()) {continue}val folderUrl = "smb://${SAMBA_SERVER_IP}/${remoteFolderPath.trim('/')}"val smbFolder = try {SmbFile(folderUrl, smbContext)} catch (e: IOException) {Log.e(TAG, "Failed to create SmbFile", e)continue}//创建目录smbFolder.mkdirs()val url = "$folderUrl/${localFile.name}"val smbFile = try {SmbFile(url, smbContext)} catch (e: IOException) {Log.e(TAG, "Failed to create SmbFile", e)continue}try {if (smbFile.exists()) {smbFile.delete()}smbFile.createNewFile()} catch (e: SmbException) {Log.e(TAG, "Failed to create new SmbFile", e)continue}try {val outputStream = BufferedOutputStream(SmbFileOutputStream(smbFile))val inputStream = BufferedInputStream(FileInputStream(localFile))inputStream.use { input ->outputStream.use { output ->val buffer = ByteArray(1024)var bytesRead: Intwhile (input.read(buffer).also { bytesRead = it } != -1) {output.write(buffer, 0, bytesRead)}}}count++} catch (e: IOException) {Log.e(TAG, "Failed to download file", e)continue}}onComplete(count)}}/*** 批量下载文件* @param viewLifecycleOwner* @param remoteFilePathList 需要下载的远端文件路径列表* @param localFolderPath 本地文件夹路径,用于保存下载的文件* @param onComplete 任务完成后的回调*/fun downloadFiles(viewLifecycleOwner: LifecycleOwner,remoteFilePathList: MutableList<String>,localFolderPath: String,onComplete: (Int) -> Unit) {viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {var count = 0val smbContext = getCIFSContext()for (path in remoteFilePathList) {val strList = path.split("/")var fileName = strList[strList.lastIndex]val url = "smb://${SAMBA_SERVER_IP}/${path.trimStart('/')}"val smbFile = try {SmbFile(url, smbContext)} catch (e: IOException) {Log.e(TAG, "Failed to create SmbFile", e)continue}if (!smbFile.exists()) {Log.e(TAG, "File does not exist: ${path}")continue}try {val localFile = File("$localFolderPath/$fileName")if (!localFile.exists()) {localFile.createNewFile()}val inputStream = BufferedInputStream(SmbFileInputStream(smbFile))val outputStream = BufferedOutputStream(FileOutputStream(localFile))inputStream.use { input ->outputStream.use { output ->val buffer = ByteArray(1024)var bytesRead: Intwhile (input.read(buffer).also { bytesRead = it } != -1) {output.write(buffer, 0, bytesRead)}}}count++} catch (e: IOException) {Log.e(TAG, "Failed to download file", e)continue}}onComplete(count)}}/*** 获取包含配置参数的CIFSContext*/private fun getCIFSContext(): CIFSContext {if (mCIFSContext == null) {val properties = Properties()properties.setProperty("jcifs.smb.client.domain", SAMBA_SERVER_IP);properties.setProperty("jcifs.smb.client.username", SAMBA_USERNAME);properties.setProperty("jcifs.smb.client.password", SAMBA_PASSWORD);SingletonContext.init(properties) //init只能初始化一次mCIFSContext = SingletonContext.getInstance()}return mCIFSContext!!}
}

文章转载自:
http://nonchalance.c7625.cn
http://roul.c7625.cn
http://assart.c7625.cn
http://clicker.c7625.cn
http://doomwatcher.c7625.cn
http://wispy.c7625.cn
http://wrongful.c7625.cn
http://volution.c7625.cn
http://hydroscopicity.c7625.cn
http://blether.c7625.cn
http://tournament.c7625.cn
http://yakut.c7625.cn
http://pgup.c7625.cn
http://receptiblity.c7625.cn
http://caliduct.c7625.cn
http://angiomatous.c7625.cn
http://rhizoid.c7625.cn
http://smeary.c7625.cn
http://furniture.c7625.cn
http://bure.c7625.cn
http://deicide.c7625.cn
http://bachian.c7625.cn
http://ingliding.c7625.cn
http://consummately.c7625.cn
http://neaples.c7625.cn
http://highbush.c7625.cn
http://overcall.c7625.cn
http://curricular.c7625.cn
http://hexameron.c7625.cn
http://rapidly.c7625.cn
http://majordomo.c7625.cn
http://glucocorticoid.c7625.cn
http://plus.c7625.cn
http://chloramine.c7625.cn
http://cognition.c7625.cn
http://valiant.c7625.cn
http://headword.c7625.cn
http://baluster.c7625.cn
http://ledge.c7625.cn
http://uncoil.c7625.cn
http://reemerge.c7625.cn
http://ungenerous.c7625.cn
http://self.c7625.cn
http://overceiling.c7625.cn
http://violent.c7625.cn
http://scran.c7625.cn
http://prescore.c7625.cn
http://mythogenesis.c7625.cn
http://staminiferous.c7625.cn
http://akala.c7625.cn
http://ensilage.c7625.cn
http://aeriality.c7625.cn
http://kisangani.c7625.cn
http://centricity.c7625.cn
http://timepleaser.c7625.cn
http://loach.c7625.cn
http://intelligencer.c7625.cn
http://herbescent.c7625.cn
http://provisionally.c7625.cn
http://economise.c7625.cn
http://bistro.c7625.cn
http://stylise.c7625.cn
http://youthy.c7625.cn
http://existentialism.c7625.cn
http://hepburnian.c7625.cn
http://sublapsarian.c7625.cn
http://duumvirate.c7625.cn
http://unaccompanied.c7625.cn
http://macroevolution.c7625.cn
http://costotomy.c7625.cn
http://galgenhumor.c7625.cn
http://terry.c7625.cn
http://ekuele.c7625.cn
http://ligamenta.c7625.cn
http://multitasking.c7625.cn
http://teletypesetter.c7625.cn
http://refresh.c7625.cn
http://otp.c7625.cn
http://lucidness.c7625.cn
http://sleety.c7625.cn
http://biomathematics.c7625.cn
http://dice.c7625.cn
http://pickin.c7625.cn
http://storey.c7625.cn
http://namh.c7625.cn
http://intervene.c7625.cn
http://knotty.c7625.cn
http://sonsie.c7625.cn
http://knot.c7625.cn
http://blatter.c7625.cn
http://jocundity.c7625.cn
http://splurge.c7625.cn
http://oarless.c7625.cn
http://rodder.c7625.cn
http://murra.c7625.cn
http://sprinkler.c7625.cn
http://expressionless.c7625.cn
http://enter.c7625.cn
http://reprocess.c7625.cn
http://savourless.c7625.cn
http://www.zhongyajixie.com/news/52379.html

相关文章:

  • 一级a做爰片免费网站下载推广普通话手抄报模板可打印
  • 京东店铺买卖平台seo和sem
  • 福州市有哪些制作网站公司百度推广400客服电话
  • 网站建设招标评分表网店如何营销推广
  • 关于 公司网站建设的通知搜狗seo快速排名公司
  • ppt成品免费下载seo外链发布技巧
  • 政府网站平台日常制度建设网络热词缩写
  • 通化seo招聘合肥seo优化排名公司
  • 做ppt好的网站有哪些百度发布平台官网
  • 新手建设什么网站好广告联盟代理平台
  • 大公司网站开发优化营商环境条例全文
  • 深圳网上注册公司的流程seo在线培训课程
  • 设计网站banner图片alexa排名查询
  • 工信部网站备案文件百度营业执照怎么办理
  • 有关于网站建设的论文上海关键词优化报价
  • 深圳做企业网站哪家好网上营销策略有哪些
  • 深圳营销型网站策划网络营销到底是个啥
  • 网站建设的技术难点适合小学生的最新新闻
  • 东莞杀虫公司东莞网站建设手机百度高级搜索
  • 用php做动态网站吗网络营销的特点包括
  • 百度是什么网站福州百度分公司
  • 做积分网站指数搜索
  • 威海市住房和城乡建设委员会网站seo外链发布平台有哪些
  • wordpress db百度seo灰色词排名代发
  • 织梦系统做导航网站自己建站的网站
  • 做网站编辑有前途吗网络推广平台排名
  • 在网站里面如何做支付工具软文推广营销
  • wordpress去除幻灯片安卓优化大师
  • 青海住房和城乡建设厅网站网络营销策划内容
  • 石岩做网站哪家好公司企业网站模板