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

  • Home
  • SEARCH
  • 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 6096353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:55:04+00:00 2026-05-23T12:55:04+00:00

Till now I had been using following code to ftp file from one location

  • 0

Till now I had been using following code to ftp file from one location to another :-

FTPUploader.java

public class FTPUploader {

    private URLConnection remoteConnection = null;

    public void connect(String userName, String hostName, String password,
            String remoteFile) {
        try {
            URL url = new URL("ftp://" + userName + ":" + password + "@"
                    + hostName + "/" + remoteFile + ";type=i");
            remoteConnection = url.openConnection();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    public void uploadFile(String fileName) {
        try {
            InputStream inputStream = new FileInputStream(fileName);
            BufferedInputStream read = new BufferedInputStream(inputStream);
            OutputStream out = remoteConnection.getOutputStream();
            byte[] buffer = new byte[1024];
            int readCount = 0;
            while ((readCount = read.read(buffer)) > 0) {
                out.write(buffer, 0, readCount);
            }
            out.flush();
            out.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Now, the problem, the machine where i login with the username/password, open at some fixed location. I am using linux machine for testing. Suppose I login with abc/123456, automatically it takes me to /local/abc location, where i can write a file.

Now I want to FTP the file to another location like /local/abc/folder1, now how to do that, after making some changes in the code above.

Thanks

  • 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-23T12:55:04+00:00Added an answer on May 23, 2026 at 12:55 pm

    You’ll have to issues ftp change directory commands. I would consider using Apache’s FTPClient for this.

    • Apache Commons Net
    • FTPClient JavaDoc
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Up till now we've been rewriting URL's using a custon 404 page: the url
We have a website; which, till now had only HTML pages. Now we are
Up till now I have been developing my personal and school projects at home
I'm new to RhinoMock's just been doing state unit testing up till now. How
I've been using nhibernate for a few months now and I am starting to
In all my projects till now, I use to use singleton pattern to access
I have a simple web page that till now didn't need any login. It
I want to play a movie file or any animation file till the time
I want to call a web service, but I won't know the url till
I implementing a EventQueue and get notified when AWTEvents are send. I wait till

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.