Hi,

I want to transfer files between 2 servers.
But Not able to find any decent tutorials.

Please suggest some.
If there's any api...then much better.

Thank You

Do you want a tutorial or some code?
Here is a function I used to send a file to a destination:

import	java.util.*;
import	java.io.*;
import	java.net.URLConnection;
import	java.net.MalformedURLException;
import	java.net.URL;

public class CSendToDest
{
	public	static	boolean	SendToDest(
         String strUser,		//
         String strPassword,	//
         String strServer,		//10.20.30.40
         String strLocalName,	//c:\\temp\\fred.txt
         String strRemoteName,	// /MPC_FILES/AUDIT_RESULTS/fred.txt
         Object strError)
	{
		boolean blnRetVal = true;

		try
		{
			String strUrl = "ftp://"+strUser+":"+strPassword+"@"+strServer+strRemoteName;
			//
			//System.out.println(strUrl);
			URL url = new URL(strUrl);
			URLConnection con = url.openConnection();
			BufferedOutputStream out = new BufferedOutputStream(con.getOutputStream());

			FileInputStream in = new FileInputStream(strLocalName);

			int i = 0;
			byte[] bytesIn = new byte[1024];
			while ((i = in.read(bytesIn)) >= 0)
			{
				out.write(bytesIn, 0, i);
			}
			out.close();
			in.close();
		}
		catch (Exception exc)
		{
			blnRetVal = false;
			strError = exc.getMessage();
		}

		return blnRetVal;
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.