Dmytro Sylaiev created NET-721:
----------------------------------

             Summary: FTPClient::retrieveFileStream returns empty stream for 
binary files when running on remote Linux
                 Key: NET-721
                 URL: https://issues.apache.org/jira/browse/NET-721
             Project: Commons Net
          Issue Type: Bug
    Affects Versions: 3.9.0
            Reporter: Dmytro Sylaiev


I have next code works differently running on my local Windows machine and on 
linux docker container when args[0] is the binary file:

 

 
{noformat}
public class Main {
    public static void main(String[] args) throws IOException {
        String fileName = args[0];
        
        System.out.println("Print " + fileName + ":");
        printFile(fileName);

    }
    private static void printFile(String fileName) throws IOException {
    FTPClient client = new FTPClient();
    try {
        client.connect(host, port);

        client.login(user, pass);
        client.enterLocalPassiveMode();
        client.setFileType(FTP.BINARY_FILE_TYPE);
        try (InputStream is = client.retrieveFileStream(fileName)) {
            client.completePendingCommand();
            while (is.available() > 0) {
                int i = is.read();
                System.out.print((char) i);
            }

            System.out.println();
        }
    } finally {
        if (client.isConnected()) {
            client.disconnect();
        }
    }
    }
}{noformat}
 

 

When running it locally I have file content printed, but also I tried with 
jetty:11.0.15-jdk11 container, I executed same jar there and got empty stream 
in result:

 

 
{noformat}
docker cp ~\codecTest\. <containerName>:/codecTest
docker exec -it <containerName> /bin/bash
root@999c8e3413cc:/codecTest/target# java -jar codecTest-1.0-SNAPSHOT.jar 
output.zip
Print output.zip:


root@999c8e3413cc:/codecTest/target#{noformat}
When I put some debug log.info line I have found that is.available() is 0 when 
executing on linux, despite I have called 
client.setFileType(FTP.BINARY_FILE_TYPE); and client.completePendingCommand();

 

 

When execute same code in the remote debug and give the jvm some time to fetch 
the stream, it works correctly. Also no problem when retieveStream for ASCII 
files (even big one)

 

FileZilla log is also OK:

 
{noformat}
(000066)11.06.2023 15:58:08 - (not logged in) (ip)> Connected on port 9021, 
sending welcome message...
(000066)11.06.2023 15:58:08 - (not logged in) (ip)> 220-FileZilla Server 0.9.60 
beta
(000066)11.06.2023 15:58:08 - (not logged in) (ip)> 220-written by Tim Kosse 
([email protected])
(000066)11.06.2023 15:58:08 - (not logged in) (ip)> 220 Please visit 
https://filezilla-project.org/
(000066)11.06.2023 15:58:08 - (not logged in) (ip)> USER <user>
(000066)11.06.2023 15:58:08 - (not logged in) (ip)> 331 Password required for 
lserver
(000066)11.06.2023 15:58:08 - (not logged in) (ip)> PASS <pass>
(000066)11.06.2023 15:58:08 - lserver (ip)> 230 Logged on
(000066)11.06.2023 15:58:08 - lserver (ip> TYPE I
(000066)11.06.2023 15:58:08 - lserver (ip)> 200 Type set to I
(000066)11.06.2023 15:58:08 - lserver (ip)> PASV
(000066)11.06.2023 15:58:08 - lserver (ip)> 227 Entering Passive Mode 
(95,67,26,232,60,72)
(000066)11.06.2023 15:58:08 - lserver (ip)> RETR output.zip
(000066)11.06.2023 15:58:08 - lserver (ip)> 150 Opening data channel for file 
download from server of "/output.zip"
(000066)11.06.2023 15:58:08 - lserver (ip)> 226 Successfully transferred 
"/output.zip"
(000066)11.06.2023 15:58:08 - lserver (ip)> disconnected{noformat}
 

 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to