Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jsch renaming file fails

Tags:

java

sftp

jsch

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

like image 327
Stephan Avatar asked Mar 05 '12 11:03

Stephan


1 Answers

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

like image 56
Gijs Overvliet Avatar answered Nov 19 '22 09:11

Gijs Overvliet