【问题标题】:Transfer file from SFTP to ADLS将文件从 SFTP 传输到 ADLS
【发布时间】:2021-06-29 13:27:14
【问题描述】:

我们目前正在探索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. 目标应该只是文件路径还是带有文件名的文件路径?

【问题讨论】:

    标签: java sftp databricks azure-data-lake sshj


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 2018-03-20
      • 2016-06-29
      • 2021-12-31
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多