【发布时间】:2013-05-01 06:45:37
【问题描述】:
我正在做一个项目,我需要使用其域、用户名和密码访问 FTP 服务器。我想保存数据并从那里检索数据。
请为此提出任何解决方案。
【问题讨论】:
我正在做一个项目,我需要使用其域、用户名和密码访问 FTP 服务器。我想保存数据并从那里检索数据。
请为此提出任何解决方案。
【问题讨论】:
寻找 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();
}
我不处理文件上传,但我认为网络上有很多例子。
【讨论】:
【讨论】: