Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ftp upload in java

807589Feb 7 2008 — edited Jul 6 2008
Hi I try connect and upload file to ftp. code:
import java.net.*;
import java.io.*;
import java.security.*;

/**
 *
 * @author mars
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try{
            URL url = new URL("ftp://login:pass@host/");

            URLConnection con = url.openConnection();
            BufferedInputStream in = new BufferedInputStream(con.getInputStream());
            FileOutputStream out = new FileOutputStream("c:/file.zip");
            
            System.out.print("url");

            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){System.out.print(e.toString());}
    }

}
and in window Output in Netbeans I have this code but nothing in my ftp. Why?
init:
deps-jar:
compile:
run:
url
BUILD SUCCESSFUL (total time: 8 seconds)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 3 2008
Added on Feb 7 2008
9 comments
1,060 views