By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,032 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

FTP via a URL

P: n/a
Che
I am using this small piece of code to try to access a file from an
ftp server

import java.net.*;
import java.io.*;

public class URLReader {
public static void main(String[] args) throws Exception {
URL url = new URL("ftp://anonymous:xx***@sunsite.unc.edu/%2Fpub/%2Fdocs/%2Frfc/rfc999.txt;type=a");

URLConnection uc = url.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
uc.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}

When I run the code I get

Exception in thread "main" java.io.FileNotFoundException:
%2Fpub/%2Fdocs/%2Frfc/
rfc999.txt
at sun.net.http://www.protocol.ftp.FtpURLConnec...m(FtpURLConnec
tion.java:333)
at URLReader.main(URLReader.java:9)
Press any key to continue . . .

But if I remove the rfc999.txt and rerun I get a directory listing

It must be something stupid.....theres a cue for a song....but I
digress....that I am doing wrong and I'd appreciate a kick in the
right direction
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Che wrote:

"Che" <st***@cheguevara.zzn.com> wrote in message
news:68**************************@posting.google.c om...
I am using this small piece of code to try to access a file from an
ftp server

import java.net.*;
import java.io.*;

public class URLReader {
public static void main(String[] args) throws Exception {
URL url = new URL("ftp://anonymous:xx***@sunsite.unc.edu/%2Fpub/%2Fdocs/%2Frfc/rfc999.txt;
type=a");
URLConnection uc = url.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
uc.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}

When I run the code I get

Exception in thread "main" java.io.FileNotFoundException:
%2Fpub/%2Fdocs/%2Frfc/
rfc999.txt
at sun.net.http://www.protocol.ftp.FtpURLConnec...m(FtpURLConnec tion.java:333)
at URLReader.main(URLReader.java:9)
Press any key to continue . . .

But if I remove the rfc999.txt and rerun I get a directory listing

It must be something stupid.....theres a cue for a song....but I
digress....that I am doing wrong and I'd appreciate a kick in the
right direction


Change your URL to:

URL url = new URL(ftp://sunsite.unc.edu/pub/docs/rfc/rfc999.txt);

or this if you still want the anonymous bit

URL url = new
URL("ftp://anonymous:xx***@sunsite.unc.edu/pub/docs/rfc/rfc999.txt");
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.