Getting file from ftp server problem.
807606Jan 26 2007 — edited Jun 10 2007Anyone can tell me what's wrong with my code.
I try to get Test.txt from my ftp server with this coding :
public class FTPClient{
public static final void main(String[] args) throws Exception
{ try {
URL url = new URL("ftp://user:password@myhost:21/MyFiles/Test.txt");
URLConnection c = url.openConnection();
BufferedReader r = new BufferedReader(new InputStreamReader(c.getInputStream()));
String l = null;
while ( (l = r.readLine()) != null)
System.out.println(l);
}
catch (Exception e)
{
System.out.println("Uh oh, got an IOException error!");
e.printStackTrace();
}
}
}
But i get the following error :
sun.net.ftp.FtpProtocolException: PORT :
at sun.net.ftp.FtpClient.openDataConnection(FtpClient.java:435)
at sun.net.ftp.FtpClient.get(FtpClient.java:550)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:382)
at FTPClient.main(FTPClient.java:8)
Can somebody help me,
What's worng with my coding..?
Thanks,