开发者

FTP file download problem. Getting readonly file exception

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 dow开发者_高级运维nloaded.
        //
       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.


I supplied the host, username and password when creating the class and then called this to download the file. Those guys were right it probably was trying to write to the root or something. I have been using commons-net-2.2.jar for this client.

public void GetFileFTP(String srcFileSpec, String destpath, String destname) {
    File pathSpec = new File(destpath);
    FTPClient client = new FTPClient();
    BufferedOutputStream fos = null;
    try {
        client.connect(mhost);
        client.login(muser, mpass);

        client.enterLocalPassiveMode(); // important!
        client.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
        fos = new BufferedOutputStream(
                              new FileOutputStream(pathSpec.toString()+"/"+destname));
        client.retrieveFile(srcFileSpec, fos);
        }//try 
        catch (IOException e) {
            Log.e("FTP", "Error Getting File");
            e.printStackTrace();
            }//catch
        finally {
            try {
                if (fos != null) fos.close();
                client.disconnect();
                }//try
                catch (IOException e) {
                    Log.e("FTP", "Disconnect Error");
                    e.printStackTrace();
                    }//catch
                }//finally
    Log.v("FTP", "Done");    
    }//getfileFTP

Hope this helps.

phavens

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜