Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

second call to storeFileStream in FTPClient returns null

I'm using apache's commons-net FTPClient to upload files.
I'm using storeFileStream method.
This works well for first call but on the second call it returns null and .getReplyStrings() returns "200 PORT command successful" !
My Code is (that is called as a method in a loop for each file):

    FileInputStream fis = null;
    File LF=new File(localFilePath);
    InputStream is = new FileInputStream(LF);

    for(String DP:(remoteBasepath+"/"+remoteFilePath).split("/")){
        if(!client.changeWorkingDirectory(DP)){
            client.makeDirectory(DP);
            client.changeWorkingDirectory(DP);
        }
    }

    for(String line:client.getReplyStrings()){
        System.out.println(line);
    }
    OutputStream os = client.storeFileStream(LF.getName());
    byte[] buffer = new byte[1024];
    int len;
    System.out.println("start");
    long RBUN=0L;
    for(String line:client.getReplyStrings()){
        System.out.println(line);
    }
    while ((len = is.read(buffer)) != -1){
        os.write(buffer, 0, len);
        os.flush();
        RBUN+=len;
        CFPRGS.setValue(Math.round((RBUN*100/LF.length())));
    }
    for(String line:client.getReplyStrings()){
        System.out.println(line);
    }
    is.close();
    os.close();

What is the problem?

like image 669
Ariyan Avatar asked Feb 22 '23 04:02

Ariyan


1 Answers

After uploading file I should call:

    client.completePendingCommand();
like image 86
Ariyan Avatar answered Feb 23 '23 18:02

Ariyan