• Post Reply Bookmark Topic Watch Topic
  • New Topic

ChannelSftp.put method changes absolute path  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


if the flag is false everything works however if its true I get below error :

As you can see with put method its changing the backslash to forwardslash.
Basically I want to use method public void put(String src, String dst,ChannelSftp.OVERWRITE) in order to move file at 'src' to 'dst' (if 'dst' has file with same name then overwrite). src = /auto/users-3/manish/emp.txt dst = /auto/users-3/manish/archive/emp.txt
Please advise what can i do so that it doesn't changes path ? I cannot put the entire code here due to compliance reason.
P.S. Files are located in unix box and um running the program from windows machine ( JVM at windowns m/c)
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manish Rajoria wrote:As you can see with put method its changing the backslash to forwardslash.

It's not the put method that's doing it, it's the java.io.File object that's used inside the FileInputStream. java.io.File on Windows treats forward slashes the same as backslashes. So as far as Java is concerned, the path was absolute from the start. If you want it relative to the current path, remove the leading slash.
 
Manish Rajoria
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob. Yes its not the put its File object.
I can't change the path. It has to be absolute unix path.
I tried to use put method which doesn't need FileInputStream

like this :

but with this I got file not found error. java.io.FileNotFoundException : c:\manish\eclipse\auto\users-3\manish\emp.txt* ( the system cannot find the path specified)

Basically I want to use csftp.put because csftp.rename doesn't seems to work when overwriting the file, hence I want to use csftp.put so that if destination has a file with same name it gets overwritten by new file.

And 1 more thing. I tested the code in my previous post ( i.e. with FileInputStream) on jvm located on unix...there path remains same but still I get this error that file not found
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use put to copy a remote file to another remote file. Just use rename, but if the file already exists first delete the old file.
 
Manish Rajoria
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob. Remove and Rename worked !!
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!