Search code examples
javaftpftp-clientapache-commons-net

How to set working directory on FTPusing FTPClient


I'm using java FTPClient for FTPconnection. This library has storeFile method for saving a file on FTP. I use it like this:

FTPClient ftpClient = new FTPClient();
//code for connection and login
...
ftpClient.storeFile("test.jpg", stream); //stream is an InputStream

Now, I need to set working directory on FTP. For example I want to save my .jpg in the specific folder. Is ftpClient.storeFile("1/test.jpg", stream); correct? Or is there another solution?


Solution

  • I think you should call FTPClient#changeWorkingDirectory() (the docs) prior to storeFile().