Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSCH: No such file error

Tags:

java

ssh

jsch

I have windows machine with running ssh server. I know the path on that machine. Let it be D:/Folder1/Folder2. I'm creating sftp channel using JSCH. But when i try to cd to D:/Folder1/Folder2, "No such file: 2" error is throwed.

can anyone please help? May be i need to convert path?

like image 774
Nem Avatar asked Jan 31 '26 09:01

Nem


1 Answers

the problem is the path. It is not finding the file to rename, if you are using the JSCH library you can use channelSftp.pwd () to know the current location.

Example:

Sftp sftp = new Sftp();
sftp.conectar();
ChannelSftp channelSftp = sftp.getChannelSftp();
channelSftp.rename(channelSftp.pwd()+"//"+file,`channelSftp.pwd()`+"//"+"new_dir//"+file);
//or
String url = channelSftp.pwd();
String url_m = channelSftp.pwd()+"/"+directory; 
channelSftp.rename(url+file,url_m+file)



 
like image 159
Faxon Lander Montenegro Avatar answered Feb 01 '26 22:02

Faxon Lander Montenegro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!