I am sending you the code, but its giving me an exception please tell me how can i handle this exception-
package remoteFileTest;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.commons.net.ftp.*;
public class AccessRemotFile {
public static void main(
String[] args) {
FTPClient ftp = null;
String usrID = "userID";
String pass = "password";
String url = "SystemIP";
//String fileName = "E:/vishal/vishal.txt";
File file = new File("E:/FOLDER/file.txt");
StringBuffer sb = new StringBuffer("ftp://");
sb.append(usrID);
sb.append(':');
sb.append(pass);
sb.append('@');
sb.append(url);
sb.append('/');
sb.append(':');
//sb.append(fileName);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
System.out.println("sb: "+sb);
try {
URL url2 = new URL(sb.toString());
URLConnection connection = url2.openConnection();
bos = new BufferedOutputStream(connection.getOutputStream());
bis = new BufferedInputStream(new FileInputStream(file.getName()));
int i;
while((i = bis.read())!=-1){
bos.write(i);
}
} catch (Exception e) {
System.out.println("Exception in AccessRemotFile: "+e);
e.printStackTrace();
}finally{
if (bis != null) try { bis.close(); } catch (Exception ioe) { /* ignore*/ }
if (bos != null) try { bos.close(); } catch (Exception ioe) { /* ignore*/ }
}
}
}
Exception :
Exception in AccessRemotFile: java.net.ConnectException:
Connection refused: connect java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.NetworkClient.openServer(Unknown Source)
at sun.net.ftp.FtpClient.openServer(Unknown Source)
at sun.net.ftp.FtpClient.openServer(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.getOutputStream(Unknown Source)
at remoteFileTest.AccessRemotFile.main(AccessRemotFile.java:42)