ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antoine Lévy-Lambert <anto...@antbuild.com>
Subject AW: ant newbie.. FTP not working..NullPointerException
Date Fri, 26 Sep 2003 11:24:32 GMT
in the implementation of FTP.java in ant 1.5.4 the line 738 is
            File file = project.resolveFile(new File(dir,
filename).getPath());

therefore you should tie your class myFirstFTP to an ant project (call the
method setProject which your class is inheriting.

Otherwise, I am not sure whether you need to extend the FTP task of ant to
do what you want, maybe you just need to use it rather than extend it.

Cheers,

Antoine

-----Urspr√ľngliche Nachricht-----
Von: Data Winner [mailto:datawinner@hotmail.com]
Gesendet: Freitag, 26. September 2003 12:36
An: user@ant.apache.org
Betreff: ant newbie.. FTP not working..NullPointerException


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.

_________________________________________________________________


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


Mime
View raw message