Solved

FTP Zip Files

Posted on 2007-11-28
3
186 Views
Last Modified: 2010-03-30
This is a second part to the my other question.

I am able to create a file on my server via FTP.  But the file has no data.

I am very new Java so any help would be great.
//****************************************************Start FTP
        File file1 = new File("c:\\target.zip");
        
        try {
        URL url = new URL("ftp://user:user@server.server.server.com/target.zip;type=i");
        URLConnection con = url.openConnection();
        FileInputStream in = new FileInputStream(file1);
        FileOutputStream out = new FileOutputStream("C:\\target.zip");
        //OutputStream out = con.getOutputStream();
        int i = 0;
        byte[] bytesIn = new byte[1024];
        while ((i = in.read(bytesIn)) > 0) {
	        out.write(bytesIn, 0, i);
        }
        out.close();
        in.close();
        } 
        catch (IOException e) {
        }    
//*************************************************End FTP

Open in new window

0
Comment
Question by:Jaziar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 20368466
0
 
LVL 9

Assisted Solution

by:ysnky
ysnky earned 50 total points
ID: 20368812
but your writing to your local file.

you have to comment this line;
FileOutputStream out = new FileOutputStream("C:\\target.zip");

and uncomment this line;
OutputStream out = con.getOutputStream();

your new code must look like;

//FileOutputStream out = new FileOutputStream("C:\\target.zip");
OutputStream out = con.getOutputStream();
0
 
LVL 92

Accepted Solution

by:
objects earned 75 total points
ID: 20369171
> as well as the changes ysnky posted you also need to change you while loop

        File file1 = new File("c:\\target.zip");
       
        try {
        URL url = new URL("ftp://user:user@server.server.server.com/target.zip;type=i");
        URLConnection con = url.openConnection();
        FileInputStream in = new FileInputStream(file1);
        OutputStream out = con.getOutputStream();
        int i = 0;
        byte[] bytesIn = new byte[1024];
        while ((i = in.read(bytesIn)) >= 0) {
                out.write(bytesIn, 0, i);
        }
        out.close();
        in.close();
        }
        catch (IOException e) {
        }    
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question