JSch - Unable to list some of the file paths having multibyte characters

97 Views Asked by At

I am trying to get the list of files from a folder location on a Windows SFTP server using JSch. One of the behavior I am seeing is:

After a certain number of characters, the file is not even getting listed and no exception is thrown.

For Ex.:

File that doesn't get listed: C:/Data/Thai-Han-Test1/All_testcases_special_characters/Special_characters/Multilinguage_Characters_list/Han/当世界需要沟通时,请用!将于年月10-12日在德国 市举行的第十届统一码国际研讨会现在开始注册。本次 - Copy2.txt

File that gets listed: C:/Data/Thai-Han-Test1/All_testcases_special_characters/Special_characters/Multilinguage_Characters_list/Han/当世界需要沟通时,请用!将于年月10-12日在德国 市举行的第十届统一码国际研讨会现在开始注册。本 - Copy3.txt

In order to get the max length of file path that can be listed, I removed one extra character 次 from the first string and it worked.

I tried with a much larger string with English characters also and it got listed too.

My question is - Is there any limitation on the character length from a JSch perspective since I am able to list both the files by doing dir on the server itself.

Below code snippet for reference where for given list of folder paths, files are added to the list.

var srcFilePathsBuffer = new ListBuffer[String]()
var srcFilePathsList = List[String]()
var folderFilesList = List[Any]()

for (sftpFolderPath <- sftpFolderPathsList) {
  c.cd(sftpFolderPath)
  folderFilesList = c.ls(sftpFolderPath).asScala.toList
  LOG.debug("folderFilesList: " + folderFilesList)
  if (folderFilesList.size > 0)
    for (i <- 0 to folderFilesList.size - 1) {
      val entry = folderFilesList(i).asInstanceOf[ChannelSftp#LsEntry]
      LOG.debug("Entry: " + entry)
      var entryName = entry.getFilename
      if (!entry.getAttrs.isDir() && !entry.getFilename.equals(".") && !entry.getFilename.equals("..")) {
        LOG.debug(entryName + " is file")
        srcFilePathsBuffer += sftpFolderPath + "/" + entryName
      }
    }
}
srcFilePathsList = srcFilePathsBuffer.toList
srcFilePathsList

Thanks for your help!

0

There are 0 best solutions below