views:

33

answers:

0
public class FtpDownloadDemo {
public static void Connection(String filename) {
    FTPClient client = new FTPClient();
    FileOutputStream fos = null;

    try {
        client.connect("ftp.domain.com");
        client.login("admin", "secret");

        //
        // The remote filename to be downloaded.
        //
       ftpClient.setFileType(FTP.IMAGE_FILE_TYPE);

        fos = new FileOutputStream(filename);

        //
        // Download file from FTP server
        //
        client.retrieveFile("/" + filename, fos);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
            client.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

}

I am using this code to download some image file. but at fos = new FileOutputStream(filename); getting file.jpeg is readonly file exception. i am using commons.net jar file for ftp connection. please help me where i am wrong.