throws IOException {
Socket socket = new Socket(proxyHost, proxyPort);
FTPCommunicationChannel communication = new FTPCommunicationChannel(
socket, "ASCII");
// Welcome message.
FTPReply r;
try {
r = communication.readFTPReply();
} catch (FTPIllegalReplyException e) {
throw new IOException("Invalid proxy response");
}
// Does this reply mean "ok"?
if (r.getCode() != 220) {
// Mmmmm... it seems no!
throw new IOException("Invalid proxy response");
}
if (style == STYLE_SITE_COMMAND) {
// Usefull flags.
boolean passwordRequired;
// Send the user and read the reply.
communication.sendFTPCommand("USER " + proxyUser);
try {
r = communication.readFTPReply();
} catch (FTPIllegalReplyException e) {
throw new IOException("Invalid proxy response");
}
switch (r.getCode()) {
case 230:
// Password isn't required.
passwordRequired = false;
break;
case 331:
// Password is required.
passwordRequired = true;
break;
default:
// User validation failed.
throw new IOException("Proxy authentication failed");
}
// Password.
if (passwordRequired) {
// Send the password.
communication.sendFTPCommand("PASS " + proxyPass);
try {
r = communication.readFTPReply();
} catch (FTPIllegalReplyException e) {
throw new IOException("Invalid proxy response");
}
if (r.getCode() != 230) {
// Authentication failed.
throw new IOException("Proxy authentication failed");
}
}
communication.sendFTPCommand("SITE " + host + ":" + port);