Reputation: 27
Good Day,
I just need you help regarding on my program.. basically my program is intend to transfer files or copy files from the local pc and transfer it to a remote site (FTP) Here is my code:
FTPClient destFtpClient = new FTPClient();
destFtpClient.connect(destIPAddressCom, intPort);
destFtpClient.login(destFtpID, destFtpPwd);
destFtpClient.enterLocalPassiveMode();
destFtpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
String newRoot = recipeRoot.toString();
File[] transFiles = new File(newRoot).listFiles();
for(File file : transFiles) {
for(int i = 0; i < transFiles.length; i++){
File destFile = new File(destTest); //destination path
//File newDestFile = new File(destFile +File.separator+file.getName()); // destination path with the file
FileInputStream fisFile = new FileInputStream(destFile);
destFtpClient.storeFile(file.getName(), fisFile);
fisFile.close();
}
}
I've got an error:
java.io.FileNotFoundException: \Test (The specified path is invalid)
but the destination folder is Test
this is the specific folder /Test/file
I hop you can help regarding on this one. Thank you in advance!
EDITED
I tried to used what @Whome said and on the first run it works then suddenly after trying to rerun it does not work and got the same error above.
destFtpClient.changeWorkingDirectory("//Test");
destFtpClient.makeDirectory("//Test");
File destFile = new File(destTest);
FileInputStream fisFile = new FileInputStream(p1dest);
destFtpClient.storeFile(file.getName(), fisFile);
Upvotes: 0
Views: 2110
Reputation: 10400
Try using ftpclient.changeWorkingDirectory("/Test")
before uploading files and possibly leading makeDirectory("/Test")
. Why do you have foreach and for(idx) loops? Once your working directory is changed then upload just using a filename without a full path.
Upvotes: 1