devxlogo

Reading Files with FTP

Reading Files with FTP

Question:
I want to create an applcation that reads a file from a host on my LAN. The file must be read by FTP. How do I do this?

Answer:
If all you need to do is retrieve a single file by FTP, the easiest way to do this is to use the URL and URLConnection classes, referencing the file FTP-style URL (e.g., ftp://ftp.java-pro.com/). If you need to list directories and check file sizes, however, a dedicated FTP package might be more in line. The code for these alternatives is already listed in other questions, so I won’t repeat it here. Take a look at the questions titled “Fetch contents of URL” to see how to use the URL class and “FTP with Java” to see how to use a dedicated FTP package. Both questions are in the Networking section of the Java section of the inquiry.com Web site.

devx-admin

Share the Post: