commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kurt Kurniawan" <kkur...@bigw.com.au>
Subject RE: NET FTPClient changeWorkingDirectory
Date Wed, 06 Apr 2005 00:42:32 GMT

Hi,

I did a little test with my own version of program.
In my case, it works fine.

I picked up a file from a W$ box and transfer to HPUX.
Imagining that you use a root access to the box, that should not be any access rights problems.
In many cases, this is the root cause.

I suggest to check with the statement: ftp.getReplyString()
to make sure that you actually logged in to the machine before picking up the file.

Good luck !

I cut and paste a part of the code that I used for testing:

public boolean executeDFTP(String intname, String filename)
  {
  	getDataFile("myMachine","xxx","ppp","/myDir","unixhp","xxx","ppp","/usr/egate/tst/mfsone",filename);

	return true;
  }
 public void getDataFile( String source,
                   String username,
                   String password,
                   String sourceFolder,
		   String target,
		   String targetUser,
		   String targetPasswd,
                   String destinationFolder,
		   String filename)
  {
    try
    {
      // Connect and logon to FTP Server
      FTPClient ftp = new FTPClient();
      FTPClient ftp2= new FTPClient();
     
     
      ftp.connect( source );
      ftp.login( username, password );
      System.out.println("Connected to source: " +
           source + ".");
      System.out.print(ftp.getReplyString());
      ftp.changeWorkingDirectory( sourceFolder );
     
      ftp2.connect( target );
      ftp2.login( targetUser, targetPasswd );
      System.out.println("Connected to target: " +
           target + ".");
      System.out.print(ftp2.getReplyString());
      ftp2.changeWorkingDirectory( destinationFolder ); //<---------- This works!
     
      java.io.InputStream ios=ftp.retrieveFileStream(filename);
      boolean isOK=ftp2.storeFile(filename,ios);
     
     
      if (isOK){
	System.out.println("The transfer was succesful !");     
      }
     
      // Logout from the FTP Server and disconnect
      ftp.logout();
      ftp.disconnect();
     
      ftp2.logout();
      ftp2.disconnect();
     
    }
    catch( Exception e )
    {
      e.printStackTrace();
    }
  }

"What I hear, I forget. What I see, I remember.
And what I do, I understand."
~ Chinese Proverb

Kurt Kurniawan
BIG W - IT

-----Original Message-----
From: Gary Yasuda [mailto:constructicons@yahoo.com]
Sent: Wednesday, 6 April 2005 5:12 AM
To: Jakarta Commons Users List
Subject: Re: NET FTPClient changeWorkingDirectory


Jeffrey,
I am trying to FTP into HP-UX and AIX systems, read a
file or capture the output of a process, and display
them into a TextArea.

TextArea resultFld = new TextArea(50,80);
FTPClient ftp = new FTPClient();
BufferedReader buffStream;
InputStream inStream = null;
String inputLine;
String path = "/etc";

ftp.connect("hostname");
ftp.login("root", "password");

// Code used for Capturing a File
ftp.changeWorkingDirectory(path); // PROBLEM
buffStream = new BufferedReader(new
InputStreamReader(ftp.retrieveFileStream("passwd")));

// Code used for a Process
Process df_proc =
Runtime.getRuntime().exec("/usr/sbin/df");
buffStream = new BufferedReader(new
InputStreamReader(df_proc.getInputStream()));

resultFld.setText("");
while (null != (inputLine = buffStream.readLine())) {
    resultFld.append(inputLine + "\n");
}
resultFld.setCaretPosition(0);
buffStream.close();
ftp.disconnect();


I am not well versed in doing remote capturing from a
single interface like this.  If you know of more
efficient ways to code this kind of functionality, I
am open to suggestions.

Gary

--- "Jeffrey D. Brekke" <jbrekke@wi.rr.com> wrote:
>
> Gary,
>
> I think you may need to give us the context ( ie:
> more code ) around
> what you are doing.  Constant string or variable
> shouldn't matter.
>
> Sometimes while I'm tracking these types of issues
> down, I write a small
> little test case with out my *application* getting
> in the way.  Maybe
> you've tried that already?
>
> Gary Yasuda wrote:
> > I am using the commons-net-1.3.0.jar libraries.
> >
> > The changeWorkingDirectory(String) requires a
> Class
> > String as the path.  If I put the path between
> double
> > quotes, the directory is changed.  If I use a
> String
> > variable, the directory is not changed.
> >
> > For example,
> > FTPClient ftp = new FTPClient();
> > ...
> > ftp.changeWorkingDirectory("/tmp");
> >
> > This will change me to the /tmp directory.
> >
> > However,
> > String dir = "/tmp";
> > ftp.changeWorkingDirectory(dir);
> >
> > For some reason, I will not be placed in the /tmp
> > directory that is assigned to a String variable.
> >
> > Even this will not work:
> > ftp.changeWorkingDirectory(dir + "/test");
> >
> > Is this is a known bug?
> >
> > Gary
=====================================================================
> Jeffrey D. Brekke                                 
> jbrekke@wi.rr.com
> Wisconsin,  USA                                   
> brekke@apache.org
>                                                    
> ekkerbj@yahoo.com
> http://www.bloglines.com/blog/jbrekke             
> ekkerbj@gmail.com



	
__________________________________
Yahoo! Messenger
Show us what our next emoticon should look like. Join the fun.
http://www.advision.webevents.yahoo.com/emoticontest

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


CAUTION: This message may contain confidential information intended only for the use of the
addressee named above. If you are not the intended
recipient of this message, any use or disclosure of this message is prohibited. If you received
this message in error please notify email Administrators immediately.  You must obtain all
necessary intellectual property clearances before doing anything other than displaying this
message on your monitor. There is no intellectual property licence.  Any views expressed in
this message are those of the individual sender and may not necessarily reflect the views
of BIG W Discount Stores.

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


Mime
View raw message