2

How do we download directory content from SFTP server recursively in Scala? Can someone please help me with an example?

def recursiveDirectoryDownload(sourcePath: String, destinationPath: String) : Unit = { 
  val fileAndFolderList = channelSftp.ls(sourcePath) 
  for(item <- fileAndFolderList)
  { 
    if(! item.getAttrs.isDir)
    { 
      ChannelSftp.get(sourcePath + “\” + item.getFilename,destinationPath +”\” + item.getFilename) 
    }
  }
}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

0

You have to call back your recursiveDirectoryDownload function, when you encounter a subfolder.

See this question for implementation in Java:
Transfer folder and subfolders using channelsftp in JSch?
It should be trivial to translate to Scala.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992