My code
URL url = new URL("ftp://user:password@server/path");
FTPClient client = new FTPClient();
System.out.println("URL host="+url.getHost()); // server
System.out.println("URL path="+url.getPath()); // /path
client.setRemoteHost(url.getHost());
if (url.getPort() > 0) {
client.setRemotePort(url.getPort());
}
String userInfo = url.getUserInfo();
String userName = "anonymous", password = "";
if (userInfo != null) {
String [] userInfos = userInfo.split(":");
password = userInfos[1];
userName = userInfos[0];
}
client.connect();
client.login(userName, password);
try {
client.put(pageFile.getAbsolutePath(), url.getPath());
}
finally {
client.quit();
}
This gives me following error:
com.enterprisedt.net.ftp.FTPException: 553 Can't open that file: No such file or directory Rename/move failure: No such file or directory
That's because the first / should be removed.
To correct this I have to:
client.put(pageFile.getAbsolutePath(), url.getPath().substring(1));
What am I doing wrong?