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 8261619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:28:17+00:00 2026-06-08T03:28:17+00:00

Using below program i am able to upload zip file on ftp server. But

  • 0

Using below program i am able to upload zip file on ftp server.
But it makes the copy of the zip file and upload the file on ftp server.
I want it should delete the file from local system and copy it to server i.e. it should move the file not copy.Please guide

public class UploadFile {
        public static void main(String args[])
        {      
            FTPClient ftp=new FTPClient();
            try {          
                int reply;  

                ftp.connect("ipadddress"); 

                ftp.login("abc", "abc"); 

                reply = ftp.getReplyCode();
                System.out.println("reply1" + reply);
                if(!FTPReply.isPositiveCompletion(reply)) 
                {             
                    ftp.disconnect();                  
                }           
                System.out.println("FTP server connected."); 
                ftp.setFileType(FTP.BINARY_FILE_TYPE);
                InputStream input= new FileInputStream("D:\\testencrypted.zip");
                String dirTree="/Vel";
                boolean dirExists = true;
                String[] directories = dirTree.split("/");
                for (String dir : directories )
                {
                    if (!dir.isEmpty() )
                    {
                        if (dirExists)
                        {
                            dirExists = ftp.changeWorkingDirectory(dir);
                        }
                        else if (!dirExists)
                        {

                            System.out.println("dir tree" + ftp.printWorkingDirectory());


                            if (!ftp.makeDirectory(dir))
                            {

                                throw new IOException("Unable to create remote directory '" + dir + "'.  error='" + ftp.getReplyString()+"'");
                                }
                            if (!ftp.changeWorkingDirectory(dir))
                            {

                                throw new IOException("Unable to change into newly created remote directory '" + dir + "'.  error='" + ftp.getReplyString()+"'");
                            }
                            System.out.println("dir tree" + ftp.printWorkingDirectory());

                        }

                        }
                    }      

                ftp.storeFile(dirTree+"/t1.zip",input);
                input.close();
                ftp.logout();        
                } 
            catch(Exception e) 
                {                      
                System.out.println("err"+ e);             
                }
            finally 
            {
                if(ftp.isConnected())
                {
                    try
                    { 
                        ftp.disconnect();

                    }
                    catch(Exception ioe)
                    {

                    }

                }

            }
            } 
    }
  • 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-06-08T03:28:20+00:00Added an answer on June 8, 2026 at 3:28 am

    So, once you’ve completed the upload (and you’re sure that it was sucessful, simply use File.delete() to remove the file from the local disk.

    File sourceFile = new File("D:\\testencrypted.zip");    
    InputStream input= new FileInputStream(sourceFile);
    
    // Upload the file...
    // Make sure you close the input stream first ;)
    
    if (!sourceFile.delete()) {
    
      System.out.println("Failed to delete " + sourceFile + " from local disk");
      sourceFile.deleteOnExit(); // try and delete on JVM exit...
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Want to be able to check in a drawing using PDMworks, but can't
The below program calculates 2 raised to the power n without using any loop,runtime
Every time I write a program of the form below using LINQ to SQL,
I need to create program that creates a XML schema like below using System.Xml.XmlSchema
I'm working on a picture select/crop program and using this code below: http://www.androidworks.com/crop_large_photos_with_android/comment-page-1#comment-969 As
I am using below code to upload excel and INSERT in mysql in php
I'm using below query to count the daily result, but now I'm make it
I'm using TCP socket connetion between a server program and a client program. Multiple
I'm using TCP socket connetion between a server program and a client program. Multiple
I am creating a winsock UDP program. code i am using is shown below.

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.