ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Data Winner" <datawin...@hotmail.com>
Subject ant newbie.. FTP not working..NullPointerException
Date Fri, 26 Sep 2003 10:35:33 GMT
Hello All
I have to use ant apache api for a java program that performs FTP 
operations. I am using apache-ant-1.5.4 and have aslo downloaded the 
NetComponents.jar for the ftp class. This jar is included in classpath.
I am succcessfully connecting to the server, but when I call any FTP method, 
I get a NullPointerException. Here is my java code:

---------------------------------------------------------------------------------------------
package ftptest;
import java.io.*;
import com.oroinc.net.ftp.*;
import org.apache.tools.ant.*;

public class myFirstFtp extends 
org.apache.tools.ant.taskdefs.optional.net.FTP
{
  public static void main(String[] args)
  {
    myFirstFtp myObj = new myFirstFtp();
    myObj.a();
  }

  public void a()
  {
    FTPClient ftpClt = new FTPClient();

    String server="192.168.0.155";
    String loginName="anonymous";
    String pass="abc";

    try
    {
      int reply;
      ftpClt.connect(server);
      System.out.println("Connected to " + server + ".");
      reply = ftpClt.getReplyCode();

      if(!FTPReply.isPositiveCompletion(reply))
      {
        ftpClt.disconnect();
        System.err.println("FTP server refused connection.");
        System.exit(1);
      }
      else
      {
        System.out.println("login is "+ ftpClt.login(loginName,pass));
        System.out.println("connection is "+ ftpClt.isConnected());
        System.out.println("change dir "+ 
ftpClt.changeWorkingDirectory("testFtp2"));

        this.sendFile(ftpClt,"C:\\myDir","\\a.txt");
        ftpClt.disconnect();
      }
    }
    catch(IOException e)
    {
      if(ftpClt.isConnected())
      {
        try
        {
          ftpClt.disconnect();
        }
        catch(IOException f)
        {
          // do nothing
        }
      }
      System.err.println("Could not connect to server.");
      e.printStackTrace();
      System.exit(1);
    }
  }
}
----------------------------------------------------------------------------------------

I get the following output:
----------------------------------------------------------------------------------------
Connected to 192.168.0.155.

login is true

connection is true

java.lang.NullPointerException

	at org.apache.tools.ant.taskdefs.optional.net.FTP.sendFile(FTP.java:738)

	at ftptest.myFirstFtp.a(myFirstFtp.java:42)

	at ftptest.myFirstFtp.main(myFirstFtp.java:11)

change dir true

Exception in thread "main"
----------------------------------------------------------------------------------------------------------

Can anyone please help me whats missing in my code?
Thanx.

_________________________________________________________________
Keep track of Singapore & Malaysia stock prices. 
http://www.msn.com.sg/money/


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message