* @throws FTPException
*/
protected static void prepareURLTransfer(URL url, FileTransferClientInterface client)
throws IOException, FTPException {
if (!url.getProtocol().equals("ftp"))
throw new MalformedURLException("Unsupported protocol: "
+ url.getProtocol());
client.setRemoteHost(url.getHost());
if (url.getPort()>0)
client.setRemotePort(url.getPort());
String userInfo = url.getUserInfo();
String userName = "anonymous", password = "";
if (userInfo!=null) {
int colonPos = userInfo.indexOf(':');
if (colonPos>=0) {
userName = userInfo.substring(0, colonPos);
if (colonPos+1<userInfo.length()-1)
password = userInfo.substring(colonPos+1);
} else
userName = userInfo;
}
client.setUserName(userName);
client.setPassword(password);
client.setDetectContentType(true);
if (url.getQuery()!=null) {
String query = url.getQuery();
String TYPE = "type=";
int typePos = query.indexOf(TYPE);
if (typePos>=0 && query.length()>typePos+TYPE.length()) {
char typeChar = query.toUpperCase().charAt(typePos+TYPE.length());
if (typeChar==FTPTransferType.BINARY_CHAR.charAt(0)) {
client.setContentType(FTPTransferType.BINARY);
client.setDetectContentType(true);
} else if (typeChar==FTPTransferType.ASCII_CHAR.charAt(0)) {
client.setContentType(FTPTransferType.ASCII);
client.setDetectContentType(true);
} else
throw new MalformedURLException("Unknown type: " + query.substring(typePos));
}
}
}