You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Diane Baumgartner <po...@yahoo.com> on 2011/07/25 22:41:54 UTC

Help with change directory

I'm new to Apache Commons  (3.0.1), and am writing a Java program to FTP a file on my local server to an FTP server on the same network.  
 
First, I'd like to make sure that changeWorkingDirectory() changes the directory on the remote machine.  It's not clear from the documentation.
 
The first thing hat happens is that the "Change Directory didn't work" prints out.  but I don't know what went wrong.  So, I'm trying to use getReply() for more information, but my program hangs on that line.  I know this becuase the line before it prints, but not the line after it.
 
Here's a code snippet:
 
FTPClient ftp = new FTPClient();
ftp.connect (server);
 
// status checking here - print statements indicate that connect was successful
 
boolean OK = ftp.changeWorkingDirectory ("/tmp/dir_name");
if {OK} {
  System.out.println ("Change directory worked");
} else {
  System.out.println ("Change directory didn't work");
  system.out.println ("The FTP Reply Code is");
  
 reply = ftp.getReply();  // reply was defined as int before doing the connect previous to this
  System.out.println (Reply);
}
 
Thanks for any help you can offer.  

Re: [NET] Help with change directory

Posted by sebb <se...@gmail.com>.
On 26 July 2011 14:49, sebb <se...@gmail.com> wrote:
> On 26 July 2011 14:41, Diane Baumgartner <po...@yahoo.com> wrote:
>> Thanks for your reply,
>>
>> I'll retest, but I believe that previous versions of the code also hung on getReplyString and getReplyCode after the change directory.
>
> Very unlikely.
>
>> Is it OK to use getReplyCode followed by getReplyString to output both the code and description?
>
> Yes, see the example code.
>
>> Also, by FTPClient example code, do you mean the examples in the JavaDoc, or are there examples somewhere else I haven't found yet?
>
> The file src/main/java/examples/ftp/FTPClientExample.java which is in
> the commons-net-3.0.1-bin archive (and the source archive).
>
>> PS - I also tried to go to the FAQ linked to by the NET main page, but it was a bad link.  Is there a specific place to report stuff like that?
>
> JIRA

But don't bother - it's been fixed (website will sync in a few hours).
Meanwhile the URL is

http://wiki.apache.org/commons/Net/FrequentlyAskedQuestions

>> Thanks again for your help.
>>
>> --- On Tue, 7/26/11, sebb <se...@gmail.com> wrote:
>>
>>
>> From: sebb <se...@gmail.com>
>> Subject: Re: [NET] Help with change directory
>> To: "Commons Users List" <us...@commons.apache.org>
>> Date: Tuesday, July 26, 2011, 7:39 AM
>>
>>
>> On 25 July 2011 21:41, Diane Baumgartner <po...@yahoo.com> wrote:
>>> I'm new to Apache Commons  (3.0.1), and am writing a Java program to FTP a file on my local server to an FTP server on the same network.
>>
>> First, please prefix the subject line with the Commons component; in
>> this case [NET] as I have done in this reply.
>>
>>> First, I'd like to make sure that changeWorkingDirectory() changes the directory on the remote machine.  It's not clear from the documentation.
>>
>> The command corresponds with the standard FTP command CWD, which
>> attempts to change the remote directory.
>>
>>> The first thing hat happens is that the "Change Directory didn't work" prints out.  but I don't know what went wrong.
>>> So, I'm trying to use getReply() for more information, but my program hangs on that line.  I know this becuase the line before it prints, but not the line after it.
>>>
>>> Here's a code snippet:
>>>
>>> FTPClient ftp = new FTPClient();
>>> ftp.connect (server);
>>>
>>> // status checking here - print statements indicate that connect was successful
>>>
>>> boolean OK = ftp.changeWorkingDirectory ("/tmp/dir_name");
>>> if {OK} {
>>>   System.out.println ("Change directory worked");
>>> } else {
>>>   System.out.println ("Change directory didn't work");
>>>   system.out.println ("The FTP Reply Code is");
>>>
>>>  reply = ftp.getReply();  // reply was defined as int before doing the connect previous to this
>>>   System.out.println (Reply);
>>> }
>>>
>>> Thanks for any help you can offer.
>>
>> getReply() is intended for low-level programming; it fetches the
>> response from the server, so no wonder the code hangs.
>>
>> You need to use getReplyCode() and/or getReplyString().
>>
>> Have a look at the FTPClientExample code.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>

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


Re: [NET] Help with change directory

Posted by sebb <se...@gmail.com>.
On 26 July 2011 14:41, Diane Baumgartner <po...@yahoo.com> wrote:
> Thanks for your reply,
>
> I'll retest, but I believe that previous versions of the code also hung on getReplyString and getReplyCode after the change directory.

Very unlikely.

> Is it OK to use getReplyCode followed by getReplyString to output both the code and description?

Yes, see the example code.

> Also, by FTPClient example code, do you mean the examples in the JavaDoc, or are there examples somewhere else I haven't found yet?

The file src/main/java/examples/ftp/FTPClientExample.java which is in
the commons-net-3.0.1-bin archive (and the source archive).

> PS - I also tried to go to the FAQ linked to by the NET main page, but it was a bad link.  Is there a specific place to report stuff like that?

JIRA

> Thanks again for your help.
>
> --- On Tue, 7/26/11, sebb <se...@gmail.com> wrote:
>
>
> From: sebb <se...@gmail.com>
> Subject: Re: [NET] Help with change directory
> To: "Commons Users List" <us...@commons.apache.org>
> Date: Tuesday, July 26, 2011, 7:39 AM
>
>
> On 25 July 2011 21:41, Diane Baumgartner <po...@yahoo.com> wrote:
>> I'm new to Apache Commons  (3.0.1), and am writing a Java program to FTP a file on my local server to an FTP server on the same network.
>
> First, please prefix the subject line with the Commons component; in
> this case [NET] as I have done in this reply.
>
>> First, I'd like to make sure that changeWorkingDirectory() changes the directory on the remote machine.  It's not clear from the documentation.
>
> The command corresponds with the standard FTP command CWD, which
> attempts to change the remote directory.
>
>> The first thing hat happens is that the "Change Directory didn't work" prints out.  but I don't know what went wrong.
>> So, I'm trying to use getReply() for more information, but my program hangs on that line.  I know this becuase the line before it prints, but not the line after it.
>>
>> Here's a code snippet:
>>
>> FTPClient ftp = new FTPClient();
>> ftp.connect (server);
>>
>> // status checking here - print statements indicate that connect was successful
>>
>> boolean OK = ftp.changeWorkingDirectory ("/tmp/dir_name");
>> if {OK} {
>>   System.out.println ("Change directory worked");
>> } else {
>>   System.out.println ("Change directory didn't work");
>>   system.out.println ("The FTP Reply Code is");
>>
>>  reply = ftp.getReply();  // reply was defined as int before doing the connect previous to this
>>   System.out.println (Reply);
>> }
>>
>> Thanks for any help you can offer.
>
> getReply() is intended for low-level programming; it fetches the
> response from the server, so no wonder the code hangs.
>
> You need to use getReplyCode() and/or getReplyString().
>
> Have a look at the FTPClientExample code.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

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


Re: [NET] Help with change directory

Posted by Diane Baumgartner <po...@yahoo.com>.
Thank you so much - the debugging line was exactly what I needed.  I am now able to ftp away!

--- On Tue, 7/26/11, sebb <se...@gmail.com> wrote:

From: sebb <se...@gmail.com>
Subject: Re: [NET] Help with change directory
To: "Commons Users List" <us...@commons.apache.org>
Date: Tuesday, July 26, 2011, 9:38 AM



I forgot to mention that you can add debug tracing (as per the example code):

        ftp.addProtocolCommandListener(new PrintCommandListener(new
PrintWriter(System.out), true));

> -----Original Message-----
> From: sebb [mailto:sebbaz@gmail.com]
> Sent: Tuesday, July 26, 2011 07:40 AM
> To: Commons Users List
> Subject: Re: [NET] Help with change directory
>
> On 25 July 2011 21:41, Diane Baumgartner <po...@yahoo.com> wrote:
>> I'm new to Apache Commons  (3.0.1), and am writing a Java program to FTP a file on my local server to an FTP server on the same network.
>
> First, please prefix the subject line with the Commons component; in this case [NET] as I have done in this reply.
>
>> First, I'd like to make sure that changeWorkingDirectory() changes the directory on the remote machine.  It's not clear from the documentation.
>
> The command corresponds with the standard FTP command CWD, which attempts to change the remote directory.
>
>> The first thing hat happens is that the "Change Directory didn't work" prints out.  but I don't know what went wrong.
>> So, I'm trying to use getReply() for more information, but my program hangs on that line.  I know this becuase the line before it prints, but not the line after it.
>>
>> Here's a code snippet:
>>
>> FTPClient ftp = new FTPClient();
>> ftp.connect (server);
>>
>> // status checking here - print statements indicate that connect was
>> successful
>>
>> boolean OK = ftp.changeWorkingDirectory ("/tmp/dir_name"); if {OK} {
>>   System.out.println ("Change directory worked"); } else {
>>   System.out.println ("Change directory didn't work");
>>   system.out.println ("The FTP Reply Code is");
>>
>>  reply = ftp.getReply();  // reply was defined as int before doing the
>> connect previous to this
>>   System.out.println (Reply);
>> }
>>
>> Thanks for any help you can offer.
>
> getReply() is intended for low-level programming; it fetches the response from the server, so no wonder the code hangs.
>
> You need to use getReplyCode() and/or getReplyString().
>
> Have a look at the FTPClientExample code.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
> ---------------------------------------------------------
>
> NOTICE: The information contained in this electronic mail message is confidential and intended only for certain recipients.  If you are not an intended recipient, you are hereby notified that any disclosure, reproduction, distribution or other use of this communication and any attachments is strictly prohibited.  If you have received this communication in error, please notify the sender by reply transmission and delete the message without copying or disclosing it.
>
> ============================================================================================
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

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


Re: [NET] Help with change directory

Posted by sebb <se...@gmail.com>.
I forgot to mention that you can add debug tracing (as per the example code):

        ftp.addProtocolCommandListener(new PrintCommandListener(new
PrintWriter(System.out), true));

> -----Original Message-----
> From: sebb [mailto:sebbaz@gmail.com]
> Sent: Tuesday, July 26, 2011 07:40 AM
> To: Commons Users List
> Subject: Re: [NET] Help with change directory
>
> On 25 July 2011 21:41, Diane Baumgartner <po...@yahoo.com> wrote:
>> I'm new to Apache Commons  (3.0.1), and am writing a Java program to FTP a file on my local server to an FTP server on the same network.
>
> First, please prefix the subject line with the Commons component; in this case [NET] as I have done in this reply.
>
>> First, I'd like to make sure that changeWorkingDirectory() changes the directory on the remote machine.  It's not clear from the documentation.
>
> The command corresponds with the standard FTP command CWD, which attempts to change the remote directory.
>
>> The first thing hat happens is that the "Change Directory didn't work" prints out.  but I don't know what went wrong.
>> So, I'm trying to use getReply() for more information, but my program hangs on that line.  I know this becuase the line before it prints, but not the line after it.
>>
>> Here's a code snippet:
>>
>> FTPClient ftp = new FTPClient();
>> ftp.connect (server);
>>
>> // status checking here - print statements indicate that connect was
>> successful
>>
>> boolean OK = ftp.changeWorkingDirectory ("/tmp/dir_name"); if {OK} {
>>   System.out.println ("Change directory worked"); } else {
>>   System.out.println ("Change directory didn't work");
>>   system.out.println ("The FTP Reply Code is");
>>
>>  reply = ftp.getReply();  // reply was defined as int before doing the
>> connect previous to this
>>   System.out.println (Reply);
>> }
>>
>> Thanks for any help you can offer.
>
> getReply() is intended for low-level programming; it fetches the response from the server, so no wonder the code hangs.
>
> You need to use getReplyCode() and/or getReplyString().
>
> Have a look at the FTPClientExample code.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
> ---------------------------------------------------------
>
> NOTICE: The information contained in this electronic mail message is confidential and intended only for certain recipients.  If you are not an intended recipient, you are hereby notified that any disclosure, reproduction, distribution or other use of this communication and any attachments is strictly prohibited.  If you have received this communication in error, please notify the sender by reply transmission and delete the message without copying or disclosing it.
>
> ============================================================================================
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

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


RE: [NET] Help with change directory

Posted by "Magid, J. (Joe)" <Jo...@us.ing.com>.
I'd also suggest doing a command line FTP connect and execute the change folder by hand to ensure that you are where you think you are when you connect - usually each login ID is assigned a particular folder location and you might not be where you think you are. 

You also may not want to include the leading / in your cwd input parm. If you are trying to do a relative directory change folder then the leading / will be trying to change you to an absolute folder location from the top of the folder tree on the drive you are connecting to.

(And I'm not sure about the earlier advice about VFS - it's got lots of capabilities, but isn't anywhere near as straight forward to work with if you're not a pretty experienced Java person, as is the case for me!)


~~~~~~~~~~~~~~~~~~~~~~~
Joe Magid 
Senior Developer
ING - Annuity Manufacturing IT Production Support
Office: (610) 425-3750 
Cell:    (610) 506-4595
Joseph.Magid@us.ing.com


-----Original Message-----
From: sebb [mailto:sebbaz@gmail.com] 
Sent: Tuesday, July 26, 2011 07:40 AM
To: Commons Users List
Subject: Re: [NET] Help with change directory

On 25 July 2011 21:41, Diane Baumgartner <po...@yahoo.com> wrote:
> I'm new to Apache Commons  (3.0.1), and am writing a Java program to FTP a file on my local server to an FTP server on the same network.

First, please prefix the subject line with the Commons component; in this case [NET] as I have done in this reply.

> First, I'd like to make sure that changeWorkingDirectory() changes the directory on the remote machine.  It's not clear from the documentation.

The command corresponds with the standard FTP command CWD, which attempts to change the remote directory.

> The first thing hat happens is that the "Change Directory didn't work" prints out.  but I don't know what went wrong.
> So, I'm trying to use getReply() for more information, but my program hangs on that line.  I know this becuase the line before it prints, but not the line after it.
>
> Here's a code snippet:
>
> FTPClient ftp = new FTPClient();
> ftp.connect (server);
>
> // status checking here - print statements indicate that connect was 
> successful
>
> boolean OK = ftp.changeWorkingDirectory ("/tmp/dir_name"); if {OK} {
>   System.out.println ("Change directory worked"); } else {
>   System.out.println ("Change directory didn't work");
>   system.out.println ("The FTP Reply Code is");
>
>  reply = ftp.getReply();  // reply was defined as int before doing the 
> connect previous to this
>   System.out.println (Reply);
> }
>
> Thanks for any help you can offer.

getReply() is intended for low-level programming; it fetches the response from the server, so no wonder the code hangs.

You need to use getReplyCode() and/or getReplyString().

Have a look at the FTPClientExample code.

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


---------------------------------------------------------

NOTICE: The information contained in this electronic mail message is confidential and intended only for certain recipients.  If you are not an intended recipient, you are hereby notified that any disclosure, reproduction, distribution or other use of this communication and any attachments is strictly prohibited.  If you have received this communication in error, please notify the sender by reply transmission and delete the message without copying or disclosing it.

============================================================================================


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


Re: [NET] Help with change directory

Posted by Diane Baumgartner <po...@yahoo.com>.
Thanks for your reply, 
 
I'll retest, but I believe that previous versions of the code also hung on getReplyString and getReplyCode after the change directory.  
 
Is it OK to use getReplyCode followed by getReplyString to output both the code and description?  
 
Also, by FTPClient example code, do you mean the examples in the JavaDoc, or are there examples somewhere else I haven't found yet?
 
PS - I also tried to go to the FAQ linked to by the NET main page, but it was a bad link.  Is there a specific place to report stuff like that?
 
Thanks again for your help.

--- On Tue, 7/26/11, sebb <se...@gmail.com> wrote:


From: sebb <se...@gmail.com>
Subject: Re: [NET] Help with change directory
To: "Commons Users List" <us...@commons.apache.org>
Date: Tuesday, July 26, 2011, 7:39 AM


On 25 July 2011 21:41, Diane Baumgartner <po...@yahoo.com> wrote:
> I'm new to Apache Commons  (3.0.1), and am writing a Java program to FTP a file on my local server to an FTP server on the same network.

First, please prefix the subject line with the Commons component; in
this case [NET] as I have done in this reply.

> First, I'd like to make sure that changeWorkingDirectory() changes the directory on the remote machine.  It's not clear from the documentation.

The command corresponds with the standard FTP command CWD, which
attempts to change the remote directory.

> The first thing hat happens is that the "Change Directory didn't work" prints out.  but I don't know what went wrong.
> So, I'm trying to use getReply() for more information, but my program hangs on that line.  I know this becuase the line before it prints, but not the line after it.
>
> Here's a code snippet:
>
> FTPClient ftp = new FTPClient();
> ftp.connect (server);
>
> // status checking here - print statements indicate that connect was successful
>
> boolean OK = ftp.changeWorkingDirectory ("/tmp/dir_name");
> if {OK} {
>   System.out.println ("Change directory worked");
> } else {
>   System.out.println ("Change directory didn't work");
>   system.out.println ("The FTP Reply Code is");
>
>  reply = ftp.getReply();  // reply was defined as int before doing the connect previous to this
>   System.out.println (Reply);
> }
>
> Thanks for any help you can offer.

getReply() is intended for low-level programming; it fetches the
response from the server, so no wonder the code hangs.

You need to use getReplyCode() and/or getReplyString().

Have a look at the FTPClientExample code.

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


Re: [NET] Help with change directory

Posted by sebb <se...@gmail.com>.
On 25 July 2011 21:41, Diane Baumgartner <po...@yahoo.com> wrote:
> I'm new to Apache Commons  (3.0.1), and am writing a Java program to FTP a file on my local server to an FTP server on the same network.

First, please prefix the subject line with the Commons component; in
this case [NET] as I have done in this reply.

> First, I'd like to make sure that changeWorkingDirectory() changes the directory on the remote machine.  It's not clear from the documentation.

The command corresponds with the standard FTP command CWD, which
attempts to change the remote directory.

> The first thing hat happens is that the "Change Directory didn't work" prints out.  but I don't know what went wrong.
> So, I'm trying to use getReply() for more information, but my program hangs on that line.  I know this becuase the line before it prints, but not the line after it.
>
> Here's a code snippet:
>
> FTPClient ftp = new FTPClient();
> ftp.connect (server);
>
> // status checking here - print statements indicate that connect was successful
>
> boolean OK = ftp.changeWorkingDirectory ("/tmp/dir_name");
> if {OK} {
>   System.out.println ("Change directory worked");
> } else {
>   System.out.println ("Change directory didn't work");
>   system.out.println ("The FTP Reply Code is");
>
>  reply = ftp.getReply();  // reply was defined as int before doing the connect previous to this
>   System.out.println (Reply);
> }
>
> Thanks for any help you can offer.

getReply() is intended for low-level programming; it fetches the
response from the server, so no wonder the code hangs.

You need to use getReplyCode() and/or getReplyString().

Have a look at the FTPClientExample code.

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


Re: Help with change directory

Posted by James Carman <jc...@carmanconsulting.com>.
Try vfs
On Jul 25, 2011 4:42 PM, "Diane Baumgartner" <po...@yahoo.com> wrote:
> I'm new to Apache Commons  (3.0.1), and am writing a Java program to FTP a
file on my local server to an FTP server on the same network.
>
> First, I'd like to make sure that changeWorkingDirectory() changes the
directory on the remote machine.  It's not clear from the documentation.
>
> The first thing hat happens is that the "Change Directory didn't work"
prints out.  but I don't know what went wrong.  So, I'm trying to use
getReply() for more information, but my program hangs on that line.  I know
this becuase the line before it prints, but not the line after it.
>
> Here's a code snippet:
>
> FTPClient ftp = new FTPClient();
> ftp.connect (server);
>
> // status checking here - print statements indicate that connect was
successful
>
> boolean OK = ftp.changeWorkingDirectory ("/tmp/dir_name");
> if {OK} {
>   System.out.println ("Change directory worked");
> } else {
>   System.out.println ("Change directory didn't work");
>   system.out.println ("The FTP Reply Code is");
>
>  reply = ftp.getReply();  // reply was defined as int before doing the
connect previous to this
>   System.out.println (Reply);
> }
>
> Thanks for any help you can offer.