请问各位
我想要执行 JAVA 到 FTP 中下载档案到电脑中
FTP 预设登入目录是 D:/test/in
但是我想要的档案在 D:/test 中
试了几个 FTPClient 提供的API
ftpClient.changeToParentDirectory();
ftpClient.changeWorkingDirectory("/test");
但是好像无法往上层目录切换,请问有解决的辨法吗? 谢谢
public class Test2 {
public static void testDownload() throws IOException {
String server = "192.168.52.1";
int port = 21;
String user = "test";
String pass = "test";
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.changeToParentDirectory();
FTPFile[] filed = ftpClient.listFiles();
System.out.println(filed[0]);
String remoteFile1 = "test/a.txt";
File dlFile = new File("D:/ddd.txt");
OutputStream outputStream1 = new BufferedOutputStream(
new FileOutputStream(dlFile));
ftpClient.retrieveFile(remoteFile1, outputStream1);
outputStream1.close();
} catch (IOException ex) {
System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public static void main(String[] args) throws IOException {
testDownload();
}
}
该贴被qq_1434338916167编辑于2015-10-23 10:04:06