// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketException;

import org.apache.commons.net.ftp.FTPClient;

public class FtpPut {
    public static void main(String[] args) {
        FTPClient client = new FTPClient();
        try {
            client.connect("localhost");
            client.login("anonymous", "arne@");
            InputStream is = new FileInputStream("C:\\z.zip");
            client.setFileType(FTPClient.BINARY_FILE_TYPE);
            OutputStream os = client.storeFileStream("z.zip");
            byte[] b = new byte[1000];
            int n;
            int total = 0;
            while((n = is.read(b)) >= 0) {
                os.write(b,0,n);
                total += n;
                System.out.println("bytes: " + total);
            }
            os.close();
            is.close();
            client.disconnect();
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
