I'm a newbie in Java socket programming and right now, I have a hard time.
I would like to make a simple java program which can connect a socket in port 21, log as anonymous user, and put a password on it, so I can log as an anonymous in a proper way. I turn on my FTP on XAMPP, and run my application on eclipse. here the code :
public class ftpClient {
Socket socket;
PrintWriter pw;
BufferedReader input;
String info = "";
public ftpClient(){
try{
socket = new Socket("localhost", 21);
System.out.println("Masuk port 21");
logUsername();
sendPassword();
closeEverything();
}
catch(IOException ioe){
System.out.println("Kesalahan dalam Socket");
}
}
public void logUsername()throws IOException{
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
pw = new P开发者_JAVA技巧rintWriter(socket.getOutputStream());
pw.write("USER anonymous\n");
pw.flush();
System.out.println(input.readLine());
}
public void sendPassword()throws IOException{
pw.write("PASS faris@gmail.com\n");
pw.flush();
System.out.println(input.readLine());
System.out.println(input.readLine());
}
public void closeEverything() throws IOException{
input.close();
pw.close();
socket.close();
}
public static void main(String[]args){
new ftpClient();
System.out.println("done");
}
}
I was told that on FTP while log as anonymous you need enter an email address as a password, and here the output.
Masuk port 21
220 ProFTPD 1.3.3 Server (ProFTPD Default Installation) [127.0.0.1]
331 Password required for anonymous
530 Login incorrect.
done
Would you mind telling the wrong part? I'm sorry for my bad coding style. Thanks
Promoted OP's comment to Answer:
Yes you are right. I haven't configure it yet. Thank you :)
加载中,请稍侯......
精彩评论