Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting file from ftp server problem.

807606Jan 26 2007 — edited Jun 10 2007
Anyone 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,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 8 2007
Added on Jan 26 2007
7 comments
360 views