Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

FTP -Jakarta Commons Net - Cannot change working directory on ftp host

843790Nov 29 2006 — edited Dec 1 2006
Hi,
I need to transfer files back and forth between localhosts and a ftp-server. I am using Jakartas Common Not 1.4.1.

I have no problem connecting and transfering files. The problem I have is, that once I have set the working directory of the ftp-connection, I cannot use changeWorkingDirectory(String str) to change it. The only change that works is changeToParentDirectory.

Can it be a trouble with the server? Or do I have some flaws in my implementation?
try{
            FTPClient ftp = new FTPClient();
            ftp.connect(this.host);
            ftp.login(this.username, this.password);        
            FileInputStream in = new FileInputStream(new File("C:\\workflow.JPG"));
            
            ftp.changeWorkingDirectory("root/firstDir/");            
            ftp.appendFile("inFirstDir.jpg", (InputStream)in );            

            ftp.changeWorkingDirectory("root/secondDir/");            
            //ftp.changeToParentDirectory();                  
            ftp.appendFile("inSecondtDir.jpg", (InputStream)in );                            
}catch(Exception e){
       System.err.println("Error");
}
If I run the code above it results in both files ending up in root/firstDir. I thought the second file would end up in root/secondDir.
If I instead use changeToParentDirectory(), the second file, inSecondtDir.jpg, ends up in the root/.

Am I supposed to disconnect and reconnect each time I want to go to a directory that is a child or a sibling to my first/current working directory?
I am quite new to the FTP-protocol...

thanks,
Jerfa
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 29 2006
Added on Nov 29 2006
5 comments
782 views