问题描述
我们目前正在探索 sshj 库以将文件从 SFTP 路径下载到 ADLS。我们使用 example 作为参考。
-
我们已经将 Databricks 中的 ADLS Gen2 存储配置为作为
abfss
URL 访问。 -
我们在 Databricks 中使用了 Scala。
-
我们应该如何在获取步骤中将
abfss
路径作为FileSystemFile
对象传递?sftp.get("test_file",new FileSystemFile("abfss://<container_name>@a<storage_account>.dfs.core.windows.net/<path>"));
解决方法
使用流。首先获取源SFTP文件的InputStream
:
RemoteFile f = sftp.open(sftpPath);
InputStream is = f.new RemoteFileInputStream(0);
(How to read from the remote file into a Stream?)
然后在 ADLS 上获取目标文件的 OutputStream
:
OutputStream os = adlsStoreClient.createFile(adlsPath,IfExists.OVERWRITE);
(How to upload and download a file from my locale to azure adls using java sdk?)
然后从第一个复制到另一个:
is.transferTo(os);
(Easy way to write contents of a Java InputStream to an OutputStream)