1
    f.connect("ftp.drivehq.com",21);
        if(f.login("XXXX", "XXX"))
        {
        f.enterLocalPassiveMode();
        f.setFileType(FTP.BINARY_FILE_TYPE);
        FileInputStream in = new FileInputStream(URL);
        result = f.storeFile(newfile, in);
        in.close();
        f.logout(); 
        f.disconnect();
        }
    It upload fine but not in particular path i also try as ftp://ftp.drivehq.com/myfolder

但它在android未知主机异常中给出错误,比如我需要在特定文件夹中上传文件所以提前感谢帮助我

4

1 回答 1

1

您好,请使用以下代码。它对我有用,我已经检查过了。

SimpleFTP ftp = new SimpleFTP();

         try
         {
            // Connect to an FTP server on port 21.

            ftp.connect("host", 21, "username", "password");

            // Set binary mode.
            ftp.bin();

            // Change to a new working directory on the FTP server.


            ftp.cwd("/httpdocs/yourdestinationfolderinftp");

            // Upload some files.
            ftp.stor(new File("/mnt/sdcard/ftp.jpg"));              

            // Quit from the FTP server.
            ftp.disconnect();

         }
         catch (Exception e) {
            // TODO: handle exception
             e.printStackTrace();
        }


    }
于 2013-02-08T06:20:38.917 回答