Using JSch, is there a way to tell if a remote file exists without doing an ls
and looping through the files to find a name match?
Thanks
You can also do something like this:
try {
channelSftp.lstat(name);
} catch (SftpException e){
if(e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE){
// file doesn't exist
} else {
// something else went wrong
throw e;
}
}
If you do an lstat on something that doesn't exist you get an SftpExecption with an id of 2, otherwise you get information about the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With