I am trying to make an FTP client from scratch in Java.
I am using Filezilla as a server and I can connect to it up to a certain point. By that I mean that I have the Command port working, but no matter how much I search I cannot get the data port to connect.
All of the websites I've looked for say the problem has to do with the firewall and/or the router, however, when I try to connect to the server with the Filezilla client everything goes well.
What I have so far:
serverSocket = new ServerSocket(20);
socket = new Socket(127.0.0.1, 21);
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
writer.write("USER " + Anonymous + "\n");
writer.flush();
writer.write("PASS " + "" + "\n");
writer.flush();
writer.write("PORT 127,0,0,1,0,14");
writer.flush();
writer.write("EPRT |1|127.0.0.1|20|");
writer.flush()
dataSocket = serverSocket.accept();
That logs me into the server and disconnects. To fix that I added an infinte while loop inside a thread (for the time being) until I can connect to the data port.