Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3616314
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:29:02+00:00 2026-05-18T22:29:02+00:00

I have written the code which downloads the file from FTP server. Since I

  • 0

I have written the code which downloads the file from FTP server. Since I have my FTP server locally and I want to access like “ftp://localhost/alfresco”. It was alfresco’s FTP.

I have the following Code

public class FtpTransfer {
public static final void main(String[] args)
{
    FTPClient ftp = new FTPClient();
    FileOutputStream br = null;
    try
    {
        ftp.connect("ftp://localhost/alfresco");
        ftp.login("admin", "admin");
        String file = "KPUB//Admin//TMM//Pickup//TMM_TO_ARTESIA_06152010220246.xml";

        br = new FileOutputStream("file");
        ftp.retrieveFile("/"+file, br);
        System.out.println("Downloaded...");
    }
    catch(IOException exception) {
        System.out.println("Error : "+exception);
    }
}
}

The following exception occurs.

Error : java.net.UnknownHostException: ftp://localhost/alfresco

Please let me know how should I give the FTP Host Address?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:29:03+00:00Added an answer on May 18, 2026 at 10:29 pm

    Here is an example demonstrating connection to a server, changing present working directory, listing files in a directory and downloading a file to some specified directory.

    package test;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.net.SocketException;
    
    import org.apache.commons.net.ftp.FTPClient;
    import org.apache.commons.net.ftp.FTPFile;
    
    public class FtpTransfer {
     public static final void main(String[] args) throws SocketException, IOException {
      FTPClient ftp = new FTPClient();
      ftp.connect("ftp.somedomain.com"); // or "localhost" in your case
      System.out.println("login: "+ftp.login("username", "pass"));
    
      ftp.changeWorkingDirectory("folder/subfolder/");
      // list the files of the current directory
      FTPFile[] files = ftp.listFiles();  
      System.out.println("Listed "+files.length+" files.");
      for(FTPFile file : files) {
       System.out.println(file.getName());
      }
       // lets pretend there is a JPEG image in the present folder that we want to copy to the desktop (on a windows machine)
      ftp.setFileType(FTPClient.BINARY_FILE_TYPE); // don't forget to change to binary mode! or you will have a scrambled image!
            FileOutputStream br = new FileOutputStream("C:\\Documents and Settings\\casonkl\\Desktop\\my_downloaded_image_new_name.jpg");
    
      ftp.retrieveFile("name_of_image_on_server.jpg", br);
      ftp.disconnect();
    
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a code in which i want to open a HTM file
I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I have code written in c, which contains some complex algorithms and I want
Hey everyone, I have written a script that downloads a zip file from a
I have an application written in wpf, which downloads some webpages, parses html code
I have a file download script that I have written, which reads files from
I have some code that downloads a plist from a web server and stores
I have written some code in JSP to download .docx files which is hosted
I have written PHP code which connects to MYSQL to look up information, sends
I have written a code which does the thing as the title says. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.