Stephan
Stephan

Reputation: 4443

Jsch renaming file fails

I am uploading a large file by SFTP over Jsch. During the upload process, the old file should be available, so I'm uploading to a temp file and rename it to the new file.

final String tmpName = dest + "_tmp";
channel.put(source, tmpName);
channel.rename(tmpName, dest);

The upload is ok but the renaming fails:

ERROR: Failed to upload files
4: Failure
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2491)
at com.jcraft.jsch.ChannelSftp.rename(ChannelSftp.java:1665)
    ...

I can't figure out where the problem is. Please help

Upvotes: 5

Views: 13575

Answers (2)

user3636759
user3636759

Reputation: 96

I have tried rename and it worked fine for me. there was another file with same and i tried to rename new file to existing one. and it worked.

so no need to check file exist or not if you want to overwrite.

Upvotes: 0

Gijs Overvliet
Gijs Overvliet

Reputation: 2691

The target file already exists. Try deleting the existing file before renaming.

Upvotes: 8

Related Questions