Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.7k views
in Java FTP by (240 points)
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?

1 Answer

0 votes
by (162k points)
You're not doing anything wrong. The server requires the slash to be removed, that's all.

Categories

...