cancel
Showing results for 
Search instead for 
Did you mean: 

Java code to test the FTP connection.

Former Member
0 Kudos

Hello All,

I want to test the connection test for the FTP using telnet.

if any one have the java code please provide me........... i want to test it in mapping.

Thanks,

Chinna

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Chinna,

Check this below code

try

{

// create Ftp instance with FTP hostname, username and password as arguments

Ftp ftp = new Ftp("ftp.myserver.com","jsmith","secret");

// establish connection

ftp.connect();

}

Catch(Exception e)

{

System.out.println("Connection is not established due to this reason"+e);

}

For your reference

http://www.jscape.com/articles/simple_ftp_using_java.html

http://www.java2s.com/Code/Java/Network-Protocol/Establishftpconnection.htm

Regards

Ramesh

Former Member
0 Kudos

You can test the FTP connection using the folowing code


import java.net.*;
   //write your code here
AbstractTrace trace = container.getTrace();
try
{
      URL url = new URL("ftp://user:user@IPAddress/sender/salary.txt");
      URLConnection yc = url.openConnection();
       yc.connect();

      }
catch( Exception e)
{
//write your message here
      trace.addInfo(e.getMessage());
}

prateek
Active Contributor
0 Kudos

May be you have interest in the J2EE based application provided in SAP Note 1085539.

Regards,

Prateek

Former Member
0 Kudos

Thanks for the reply.

I want to check the connection test in the mapping.

for example if we want to test the FTP connection we can write the UDF and check the connection.

check the code for FTP connection test.

String checkFTP(String server,String username,String password,Container container){

boolean status=false;

try

{

FTPClient f=new FTPClient();

f.connect(server);

status=f.login(username, password);

if(status)

f.disconnect();

}

catch(Exception e)

{

}

if(status)

return "FTPOK";

else

return "FTPNOTOK";

In the same way i want to test the FTP connection using TELNET.

if any one have code please provide me.

Thanks,

chinna