Java why java ftp uploads file corrupted

I’m trying to upload image to my server but when I’m trying to open this image – it’s not possible to open, apparently because it’s corrupted. Can someone help me and tell me why? thanks!
I’m using the Apache Commons Net jar.

String hostName = "host";
String username = "username";
String password = "pass";
String location = "filePath.png";
FTPClient ftp = null;

InputStream in = null;
try {
    ftp = new FTPClient();
    ftp.connect(hostName);
    ftp.login(username, password);

    ftp.changeWorkingDirectory("/pictures");

    int reply = ftp.getReplyCode();
    System.out.println("Received Reply from FTP Connection:" + reply);

    if(FTPReply.isPositiveCompletion(reply))
    {
        System.out.println("Connected Success");
    }

    ftp.setFileType(FTP.BINARY_FILE_TYPE);

    File f1 = new File(location);
    in = new FileInputStream(f1);

    ftp.storeFile("fileName.png",in);

    System.out.println("SUCCESS");

    in.close();
    ftp.logout();
    ftp.disconnect();
} catch (Exception e) {
    e.printStackTrace();
}

Answer

My antivirus was blocking it..

Leave a Reply

Your email address will not be published. Required fields are marked *