0

我正在做一个项目,我需要使用其域、用户名和密码访问 FTP 服务器。我想保存数据并从那里检索数据。

请为此提出任何解决方案。

4

2 回答 2

0

寻找 commons net apache 库 - http://commons.apache.org/proper/commons-net/。它提供了使用 FTP 的工具。

下载视频文件的代码示例。

    FileOutputStream videoOut;
    File targetFile = new File("path");

    FTPClient ftpClient = new FTPClient();
    try {
        ftpClient.connect("your.ftp.address", 21);
        ftpClient.enterLocalPassiveMode();
        ftpClient.login("login", "password");

        ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);// Used for video
        targetFile.createNewFile();
        videoOut = new FileOutputStream(targetFile);
        boolean result=ftpClient.retrieveFile("/" + "filename-to-download", videoOut);

        ftpClient.disconnect();
        videoOut.close();    

    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e){
        e.printStackTrace();
    }

我不使用文件上传,但我认为 web 中有很多示例。

于 2013-05-01T06:48:07.650 回答
0

To Upload file,我在一个项目中使用了此代码。我从这个链接得到代码:FTPS

此外,这些家伙正在以安全的方式使用它。

我希望这可以帮助你。

于 2013-05-01T06:58:46.030 回答