使用apache commons连接到FTP时出错

时间:2018-02-28 22:43:38

标签: java android file permissions ftp

我使用apache公共库连接到Android应用程序的FTP。 现在我想将一个文件从内部存储器上传到FTP服务器,我从getReplyString()方法得到了这个回复。

我得到这个消息

553无法打开该文件:权限被拒绝

//将文件写入内部存储

String path = "/sdcard/";
    File file = new File(path, fileName);
    FileOutputStream stream = null;
    try {
        stream = new FileOutputStream(file);
        stream.write(jsonObject.toString().getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // Read the file from resources folder.

    try {
        File file1 = new File(path, fileName);
        Log.d("path",file1.getPath());
        BufferedInputStream in = new BufferedInputStream (new FileInputStream (file1.getPath()));
        client.connect(FTPHost);
        client.login(FTPUserName, FTPPassword);
        client.enterLocalPassiveMode();
        client.setFileType(FTP.BINARY_FILE_TYPE);
        // Store file to server

        Log.d("reply",client.getReplyString());
        boolean res = client.storeFile("/"+fileName, in);
        Log.d("reply",client.getReplyString());
        Log.d("result",res+"");
        client.logout();

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            client.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

1 个答案:

答案 0 :(得分:0)

link将文件上传到FTP服务器