如何在java中使用FTPClient选择要上传的文件夹?

时间:2011-02-15 00:06:58

标签: java ftp ftp-client apache-commons-net

我有以下代码,使用ftp host:ftp.aydeena.com但不想将文件上传到根目录。因为我想将它上传到以下路径:

ftp.aydeena.com/facebook/profileimages/

我该怎么做?

FTPClient con = new FTPClient();
        String status="";
        try{

            con.connect("ftp.aydeena.com");
            if (con.login("user", "pass")){
                con.enterLocalPassiveMode(); // important!
                con.changeWorkingDirectory("/facebook/profileimages/");
                String data = "test data";
                ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());
                boolean result = con.storeFile(Path, in);
                in.close();
                if (result) Log.v("upload result", "succeeded");
                status ="succeeded" ;
                con.logout();
                con.disconnect();
            }
        }
        catch (Exception e){
            e.printStackTrace();
            status= "Error : "+e.getMessage();
        }

0 个答案:

没有答案