主要提供python和java对私服Artifactory使用用户和密码或者oken上传和下载功能,
版本artifactory==0.1.17
from artifactory import ArtifactoryPath
import tarfile
username = "demo"
password = "demo"
token = "eyJ2ZXIiOi"
# Download Artifacts
def download(download_url):
download_path = ArtifactoryPath(download_url, auth=(username, password))
# download_path = ArtifactoryPath(download_url, auth=(username, token))
with download_path.open() as fd:
with open(r"D:\download\test-tensorflow-gpu.tar", "wb") as out:
out.write(fd.read())
# Update Artifacts
def upload(upload_url):
upload_path = ArtifactoryPath(upload_url, auth=(username, password))
if not upload_path.exists():
upload_path.mkdir()
upload_path.deploy_file(r"D:\tensorflow-gpu-1.12.0.tar")
if __name__ == '__main__':
download_url = "http://ip:port/artifactory/test/tensorflow-gpu-1.12.0.tar"
download(download_url)
upload_url = "http://ip:port/artifactory/test"
upload(upload_url)
版本
<dependency>
<groupId>org.jfrog.artifactory.client</groupId>
<artifactId>artifactory-java-client-services</artifactId>
<version>2.8.3</version>
</dependency>
基于Token认证下载代码
try {
Artifactory build = ArtifactoryClientBuilder.create().setUrl(host).setAccessToken(token).build();
InputStream inputStream = build.repository(repoName).download(path).doDownload();
entity.setInputStream(inputStream);
} catch (Exception e) {
LOG.error("下载失败", e);
}