【问题标题】:Pass Credentials to access Network Drive using Groovy使用 Groovy 传递凭据以访问网络驱动器
【发布时间】:2021-06-09 16:29:10
【问题描述】:

我需要自动将文件从一个共享驱动器位置复制到另一个共享驱动器。我已指示使用 Groovy。

我对 Groovy 完全陌生。我设法使用 targetlocation

任何帮助将不胜感激。

【问题讨论】:

  • 什么样的共享驱动器?

标签: groovy groovy-console


【解决方案1】:

如果是 Windows 或 Samba 共享,可以使用 jcifs 连接:

import jcifs.smb.SmbFile
import jcifs.smb.NtlmPasswordAuthentication
import jcifs.context.BaseContext
import jcifs.CIFSContext
import jcifs.config.PropertyConfiguration
import jcifs.Configuration

Configuration config = new PropertyConfiguration(new Properties())
CIFSContext context = new BaseContext(config)
context = context.withCredentials(new NtlmPasswordAuthentication(null, domain, userName, password))
SmbFile share = new SmbFile(url, context)

然后您可以复制所需的文件。

【讨论】:

  • 非常感谢。它是一个 Windows 共享驱动器。我会尝试并更新你。
猜你喜欢
  • 2019-10-14
  • 1970-01-01
  • 1970-01-01
  • 2016-04-22
  • 2017-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多