0

I have a program in Java that uses ftp4j library to upload pictures to FTP server. Sometimes the images are fine but sometimes the bottom half of them is either black or don't exist at all (kinda like cut). What could be the reason to it and how to fix it? The mode for uploading is set on binary.

The code

try{
        client.connect(serverName);
        client.login(serverUser, serverPass);
        System.out.println("Connection with the server created");
        if(serverHome == null){
            serverHome = "";
        }
        client.changeDirectory(serverHome+"/screenshotuploader/users/"+user);
        int count = new IOCounter().FileReader("count.txt");

        client.setType(FTPClient.TYPE_BINARY);
        client.upload(new java.io.File("screenshots/screen"+(count-1)+".png"));
        System.out.println("Screenshot nr "+(count-1)+" has been uploaded");
        SystemTray notif = new SystemTray();
        notif.Bubble(0);
        Clipboard.setClipboard(new IOCounter().FTPtoHTTP(serverName)+
                "/screenshotuploader/users/"+user+"/screen"+(count-1)+".png");

        //Shows entire file list in the folder
        String dir = client.currentDirectory();
        FTPFile[] list = client.list();
        for (int i=0; i < list.length; i++){
            System.out.println(list[i]);
        }

        client.disconnect(true);
    }
    catch (IllegalStateException | IOException | FTPIllegalReplyException | 
            FTPException | FTPDataTransferException | FTPAbortedException | 
            FTPListParseException e){
        e.printStackTrace();
        System.out.println("Something went wrong with uploading the image");
        SystemTray notif = new SystemTray();
        notif.Bubble(1);
    }

I have not tried active passive mode as I am behind a router and I thought I can't make active connection like that.

Karuvägistaja
  • 293
  • 1
  • 8
  • 17
  • 2
    Can you show us the code in which you upload the pictures? – brimborium Jun 19 '12 at 11:50
  • 1
    Do you close the stream after uploading? –  Jun 19 '12 at 12:22
  • 1
    have you tried to change Active/passive mode ? – Houcem Berrayana Jun 19 '12 at 12:34
  • OK, I'm not sure really. The catch block never gets hit? Shouldn't be a problem but are you overwriting files at any point? Are the files ok before upload? Is is threaded? Maybe try it for just one file with just the upload code? Sorry I can't be more help.. –  Jun 19 '12 at 13:23
  • The catch block sometimes get's hit but it's rare, sometimes if the server doesn't respond or something. Overwriting files don't matter, sometimes they are ok, sometimes they are cut off. All the files are ok before upload :) – Karuvägistaja Jun 19 '12 at 13:34
  • using the latest version of ftp4j? –  Jun 19 '12 at 13:39
  • I give up, sorry. My only other suggestion would be to implement the listener, it seems to give you more control of the communications anyway.. –  Jun 19 '12 at 13:47

0 Answers0