• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ChannelSftp.put method changes absolute path

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob. Remove and Rename worked !!
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
reply
    Bookmark Topic Watch Topic
  • New Topic