Ftp文件上传 - android

时间:2014-06-13 06:50:30

标签: android ftp ftp-client

我正在尝试将图像文件上传到ftp服务器。连接和登录成功但是uplaod总是返回550访问被拒绝。

这是我的代码

FTPClient client = new FTPClient();
        FileInputStream fis = null;
        int reply = 0;
        try {
            fis = new FileInputStream(new File(lastImageName));
            Log.i("file_path", lastImageName);
            client.connect("xxx.xxx.xxx.xxx", 21);
            reply = client.getReplyCode();
            Log.i("ftp_connect reply", reply + " "+client.getReplyString());
            boolean loginStatus = client.login("test", "test");
            Log.i("login_success??", loginStatus + " "+ client.getReplyString());
            client.pasv();
//          client.enterRemotePassiveMode();
            client.enterLocalPassiveMode();
            client.changeWorkingDirectory("abc");
            client.setFileType(FTP.BINARY_FILE_TYPE);

            boolean uploadstatus = client.storeFile("/abc", fis);
            // int uploadstatus2 = client.stor(lastImageName);
            String stringReply = client.getReplyString();
            Log.i("upload_success??", uploadstatus + " " + stringReply);

            client.logout();
            client.disconnect();

但是我尝试使用fireFTP上传文件它可以工作。我没有得到访问被拒绝错误。 有什么建议吗?

1 个答案:

答案 0 :(得分:1)

删除它:

boolean uploadstatus = client.storeFile("/abc", fis);

用这个:

boolean uploadstatus = client.storeFile("abc", fis);