0

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

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by thines01
0

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;
	}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.