[ https://issues.apache.org/jira/browse/VFS-857?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17927321#comment-17927321 ]
Gary D. Gregory commented on VFS-857: ------------------------------------- Hello [~imranansari] Is it possible that the "OPTS UTF8 true" syntax is specific to your server? There is an expired RFC for "UTF-8 Option for FTP" here: https://datatracker.ietf.org/doc/html/draft-ietf-ftpext-utf-8-option-00 The syntax in the RFC is: {code} OPTS <SP> UTF-8 [ <SP> NLST ] <CRLF> {code} This feature should be handled in Commons Net since Commons VFS configures a Net FTP client. This needs more research... > listFiles() fails if the FTP Server (IIS based) contains any file with name > in non-ascii Unicode character > ---------------------------------------------------------------------------------------------------------- > > Key: VFS-857 > URL: https://issues.apache.org/jira/browse/VFS-857 > Project: Commons VFS > Issue Type: Bug > Affects Versions: 2.9.0, 2.10.0 > Environment: Microsoft IIS based FTP Server > !image-2025-02-14-19-24-23-511.png! > Reporter: imran ansari > Priority: Critical > Attachments: Output.png, image-2025-02-14-19-24-23-511.png > > > FTPClient method listFiles() fails if the FTP Server contains a file with > name in non-ascii Unicode character. This is mainly reported if the server is > {*}Microsoft IIS based{*}. > > VFS2 is not sending "OPTS UTF8 true" in the request for list files. > The following code does not have any effect in case the FTP Server is IIS. > {code:java} > confBuilder.setControlEncoding(options, StandardCharsets.UTF_8.displayName()); > confBuilder.setAutodetectUtf8(options, Boolean.TRUE); > confBuilder.setFileType(options, FtpFileType.BINARY);{code} > org.apache.commons.vfs2.FileSystemException: Could not find files in > "ftp://192.168.100.8/" > {code:java} > package org.example; > import org.apache.commons.vfs2.FileObject; > import org.apache.commons.vfs2.FileSystemManager; > import org.apache.commons.vfs2.FileSystemOptions; > import org.apache.commons.vfs2.VFS; > import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; > public class Main { > public static void main(String[] args) { > // FTP server details > String host = "192.168.100.8"; > String username = "imran"; > String password = "xxxxxxx"; > String remoteDir = "/"; > try { > System.setProperty("file.encoding", "UTF-8"); > FileSystemManager fsManager = VFS.getManager(); > FileSystemOptions opts = new FileSystemOptions(); > FtpFileSystemConfigBuilder.getInstance().setAutodetectUtf8(opts, > true); > FtpFileSystemConfigBuilder.getInstance().setControlEncoding(opts, > "UTF-8"); > FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, > false); > FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, > true); > String ftpUrl = "ftp://" + username + ":" + password + "@" + host > + remoteDir; > FileObject remoteFolder = fsManager.resolveFile(ftpUrl, opts); > FileObject[] files = remoteFolder.getChildren(); > System.out.println("Files in " + remoteDir + ":"); > for (FileObject file : files) { > String fileName = file.getName().getBaseName(); > System.out.println(fileName); > } > remoteFolder.close(); > } catch (Exception e) { > e.printStackTrace(); > } > } > } > {code} > > {code:java} > <?xml version="1.0" encoding="UTF-8"?> > <project xmlns="http://maven.apache.org/POM/4.0.0" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 > http://maven.apache.org/xsd/maven-4.0.0.xsd"> > <modelVersion>4.0.0</modelVersion> > <parent> > <groupId>org.example</groupId> > <artifactId>VFS2Test</artifactId> > <version>1.0-SNAPSHOT</version> > </parent> > <artifactId>Test</artifactId> > <properties> > <maven.compiler.source>17</maven.compiler.source> > <maven.compiler.target>17</maven.compiler.target> > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> > </properties> > <dependencies> > <dependency> > <groupId>commons-net</groupId> > <artifactId>commons-net</artifactId> > <version>3.11.1</version> > </dependency> > <dependency> > <groupId>org.apache.commons</groupId> > <artifactId>commons-vfs2</artifactId> > <version>2.10.0</version> > </dependency> > </dependencies> > </project>{code} > > {panel:title=Stack Trace} > Caused by: org.apache.commons.vfs2.FileSystemException: Could not find files > in "ftp://192.168.100.8/". > at > org.apache.commons.vfs2//org.apache.commons.vfs2.provider.AbstractFileObject.findFiles(AbstractFileObject.java:1016) > at > org.apache.commons.vfs2//org.apache.commons.vfs2.provider.AbstractFileObject.listFiles(AbstractFileObject.java:1664) > at > org.apache.commons.vfs2//org.apache.commons.vfs2.provider.AbstractFileObject.findFiles(AbstractFileObject.java:991) > ... 18 more > Caused by: java.nio.file.InvalidPathException: Illegal char <?> at index 49: > /Best Practices & Guidelines/???? ???? ????? ???? ?? ???? ?? ????? ???? > ?????.docx > at > java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) > at > java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153) > at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) > at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92) > at > java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:232) > at java.base/java.nio.file.Path.of(Path.java:147) > {panel} -- This message was sent by Atlassian Jira (v8.20.10#820010)