0

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!

Dwarrior
  • 687
  • 2
  • 10
  • 26
  • 1
    Can you list that file using any SFTP client? – Martin Prikryl Aug 20 '19 at 06:53
  • Hi Martin, Thank you. I totally forgot to check using a different SFTP client, was only doing cd on the server. I am not able to list the file using winscp or filezilla also. Is this an SFTP limitation? I am unable to find any documentation that states this. I believe, in that case I just need to manually crosscheck if any file is getting missed during listing as there is no exception that can be thrown. Am I correct. – Dwarrior Aug 20 '19 at 19:24
  • I tried listing the files using SMB protocol and it displays the file correctly. Looks like it is more of a protocol issue rather than OS or config issue. – Dwarrior Aug 21 '19 at 02:40
  • SFTP protocol should not have a problem with any file name. It's rather a bug in your SFTP server. – Martin Prikryl Aug 21 '19 at 05:25
  • @MartinPrikryl - From same server, I was able to display the file using SMB protocol. I tried listing the same file from a different SFTP server also on Unix and it failed. – Dwarrior Aug 21 '19 at 12:24
  • @MartinPrikryl - I tested with few of the strings around 255 to 258 bytes character length. What I observed was any string > 256 bytes is causing issue with listing of file from other sftp clients as well. Kindly let me know if you have any other thoughts. – Dwarrior Aug 23 '19 at 15:20
  • It's still limitation of your SFTP server or maybe of the remote operating system or a file system. From a programming point of view it does not matter – This is not a programming question. – Martin Prikryl Aug 25 '19 at 06:43

0 Answers0