【问题标题】:Ftp upload file in perticular path by androidFtp通过android在特定路径上传文件
【发布时间】:2013-01-23 20:37:36
【问题描述】:
    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 未知主机异常中出现错误,例如我需要在特定文件夹中上传文件所以提前感谢帮助我

【问题讨论】:

  • 请发布您的 logcat 文件

标签: android upload path ftp


【解决方案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();
        }


    }

【讨论】:

    猜你喜欢
    • 2015-04-21
    • 2012-04-26
    • 2013-03-24
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    相关资源
    最近更新 更多