Domanda

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

È stato utile?

Soluzione

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top