Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
431 views
in Java FTP by (120 points)

Every time I try to upload a file containing an extended character (Ex: ?) as part of the filename, I receive an java.io.IOException with the message 'Unknown error'.

Uploading a file with this name using a different FTP client (Ex: WinSCP) succeeded, so the server supports the extended characters.

Trace of thrown exception:

java.io.IOException: Unknown error.
    at com.enterprisedt.net.j2ssh.sftp.SftpFileOutputStream.b(SftpFileOutputStream.java:163)
    at com.enterprisedt.net.j2ssh.sftp.SftpFileOutputStream.close(SftpFileOutputStream.java:192)
    at java.io.FilterOutputStream.close(FilterOutputStream.java:160)
    at com.enterprisedt.net.ftp.ssh.SSHFTPOutputStream.close(SSHFTPOutputStream.java:259)
    at com.inmoment.FtpService_UT.rawEdtFTPjProTest_withExtendedCharInFilename(FtpService_UT.java:243)

Sample code demonstrating the problem:

    @org.junit.Test
    public void rawEdtFTPjProTest_withExtendedCharInFilename() throws Exception {

        com.enterprisedt.net.ftp.SecureFileTransferClient client = new com.enterprisedt.net.ftp.SecureFileTransferClient(1, 1);
        client.setTimeout(30000);
        client.setServerValidationEnabled(false);
        client.setRemoteHost(host);
        client.setUserName(username);
        client.setPassword(password);
        client.setProtocol(com.enterprisedt.net.ftp.Protocol.SFTP);
        client.setRemotePort(22);

        // Use passive mode
        client.getAdvancedFTPSettings().setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.PASV);
        try {
            client.connect();
            try(OutputStream outputStream = client.uploadStream("Test file with extended char - ?.txt")) {
                byte[] contents = "This file was sent as a test.".getBytes();
                outputStream.write(contents);
            }
        } finally {
            if (client.isConnected()) {
                client.disconnect(true);
            }
        }
    }

1 Answer

0 votes
by (162k points)
There's a method for setting the character set for the control connection.

Categories

...