将文件从 SFTP 传输到 ADLS

问题描述

我们目前正在探索 sshj 库以将文件从 SFTP 路径下载到 ADLS。我们使用 example 作为参考。

  • 我们已经将 Databricks 中的 ADLS Gen2 存储配置为作为 abfss URL 访问。

  • 我们在 Databricks 中使用了 Scala。

  1. 我们应该如何在获取步骤中将 abfss 路径作为 FileSystemFile 对象传递?

    sftp.get("test_file",new FileSystemFile("abfss://<container_name>@a<storage_account>.dfs.core.windows.net/<path>"));
    
  2. 目标应该是仅文件路径还是带有文件名的文件路径?

解决方法

使用流。首先获取源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)