?
Solved

FTP Zip Files

Posted on 2007-11-28
3
Medium Priority
?
191 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 200 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

770 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