Solved

FTP Zip Files

Posted on 2007-11-28
3
182 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse package explorer vs project explorer view 2 84
compre toata in where clue oracle 4 56
JUnit 4 @Before and @BeforeClass differences 3 48
difference of if loops 23 41
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now