user3073180
user3073180

Reputation: 65

AIX 5.3 system returning ? for special characters in filenames

I am trying to get filenames containing special characters on an AIX 5.3 system using a Java program but its replacing the special characters with a question mark. This is in client environment. But when I use the same program in our dev environment, I cant reproduce the issue.

I tried both vfs2 and jsch libraries but same issue on both of them. This is the sample code I have tried-

package com.example.ftp;

import com.jcraft.jsch.*;
import java.util.Vector;

public class Elmer1 {
    public static void main(String[] args) {
        String host = "aix";
        String username = "user";
        int port = 22;
        String password = "pass";  // Replace with your password
        String remoteDirectory = "/disk1/users/usr1";  // Replace with the remote folder path

        JSch jsch = new JSch();
        Session session = null;

        try {
            // Create the session object
            session = jsch.getSession(username, host, port);
            session.setPassword(password);  // Set password

            // Create properties for key exchange, ciphers, and host key algorithms
            java.util.Properties config = new java.util.Properties();

            session.setConfig(config);

            // Disable strict host key checking for testing purposes (optional)
            session.setConfig("StrictHostKeyChecking", "no");

            // Connect to the session
            session.connect();

            // Open an SFTP channel
            ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp");
            channelSftp.connect();

            // List files and directories in the remote directory
            Vector<ChannelSftp.LsEntry> list = channelSftp.ls(remoteDirectory);

            System.out.println("Contents of " + remoteDirectory + ":");
            for (ChannelSftp.LsEntry entry : list) {
                if (entry.getAttrs().isDir()) {
                    // It's a directory
                    System.out.println("[DIR]  " + entry.getFilename());
                } else {
                    // It's a file
                    System.out.println("[FILE] " + entry.getFilename());
                }
            }

            // Disconnect when done
            channelSftp.disconnect();
            session.disconnect();

        } catch (JSchException | SftpException e) {
            e.printStackTrace();
        }
    }
}

Output in dev environment-

Contents of /disk1/users/usr1:
[DIR]  .
[DIR]  ..
[FILE] 99-4±±±±0A02-|PART±ASSEMBLY,±SAMPLE±IV-X.model

Not sure what could be causing this issue in the customer environment. Appreciate any pointers/ inputs to try to fix this problem.

Upvotes: 1

Views: 79

Answers (1)

Lorinczy Zsigmond
Lorinczy Zsigmond

Reputation: 1910

  1. Install the same localization-packages on the production host that are installed on the development host, e.g.

     bos.loc.com.utf     Common Locale Support - UTF-8
     bos.loc.iso.en_US   Base System Locale ISO Code Set - U.S. English
     bos.loc.utf.EN_US   Base System Locale UTF Code Set - U. S. English
    
  2. Make sure environment variable LC_CTYPE is set the same way on the production host as it is on develepment host. (Java properties file.encoding and sun.jnu.encoding are set based on LC_CTYPE)

  3. Try your best not to have non-ASCII characters in your file-names. Those are nothing but trouble.

Upvotes: 0

Related Questions