I am trying to place a file into SFTP directory using JSch.
channelSftp.cd(destDir);
channelSftp.put(new FileInputStream(filePath), filePath.substring(filePath.lastIndexOf(File.separatorChar)));
But the above code is placing the file always in the SFTP user home directory instead of destDir
. For example, if I create a subdirectory test
under user home directory and set destDir
as channelSftp.getHome()+"test"
, still the file is being copies to user home directory only instead of test sub-directory.
I tried to list files in destDir
(test
sub-directory), it is showing all files/directories under test
directory.
Vector<com.jcraft.jsch.ChannelSftp.LsEntry> vv = channelSftp.ls(destDir);
if(vv != null) {
for(int ii=0; ii<vv.size(); ii++){
Object obj=vv.elementAt(ii);
if(obj instanceof LsEntry){
System.out.println(((LsEntry)obj).getLongname());
}
}
}
Any suggestions? I looked at permissions (test
sub-directory has exactly same permissions as SFTP user home directory).