public void header() throws IOException {
try {
URL url = new URL(getFile());
String pwd = "";
int port = url.getPort();
socket = new Socket(url.getHost(), port == -1 ? url
.getDefaultPort() : port);
socket.setSoTimeout(((FtpService) connection.element).timeout);
ps = new PrintStream(socket.getOutputStream());
r = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
receive();
String user = "USER";
String pass = "PASS";
String userinfo = url.getUserInfo();
if (userinfo == null) {
user += " anonymous";
pass += " yourname@yourcompany.com";
} else {
StringTokenizer st = new StringTokenizer(url.getUserInfo(), ":");
user += " " + st.nextToken();
pwd = st.nextToken();
pass += " " + pwd;
}
send(user);
if (result.startsWith("530 ")) {
super.header();
code = ServerStream.UNAUTHORIZED;
return;
}
send(pass);
if (result.startsWith("530 ") || result.startsWith("503 ")) {
super.header();
code = ServerStream.UNAUTHORIZED;
return;
}
send("TYPE I");
send("PASV");
StringTokenizer st = new StringTokenizer(result.substring(result
.indexOf('(') + 1, result.indexOf(')')), ",");
socket2 = new Socket(st.nextToken() + '.' + st.nextToken() + '.'
+ st.nextToken() + '.' + st.nextToken(), Integer.valueOf(
st.nextToken()).intValue()
* 256 + Integer.parseInt(st.nextToken()));
socket2.setSoTimeout(((FtpService) connection.element).timeout);
out = new BufferedOutputStream(socket2.getOutputStream());