Spring Integration SFTP fileExistsMode for mv operation

74 Views Asked by At

Why is not possible use FileExistsMode in case of mv operation? Is FAIL default value for mv operation?

AbstractRemoteFileOutboundGateway.Command.MV
.fileExistsMode(FileExistsMode.REPLACE)

enter image description here

Why not in MV case? Maybe pull request in next ver?

2

There are 2 best solutions below

0
Artem Bilan On

The logic there in the SftpSession is like this:

public void rename(String pathFrom, String pathTo) throws IOException {
    if (this.sftpClient.getVersion() >= SftpConstants.SFTP_V5) {
        this.sftpClient.rename(pathFrom, pathTo, SftpClient.CopyMode.Overwrite);
    }
    else {
        remove(pathTo);
        this.sftpClient.rename(pathFrom, pathTo);
    }
}

So, it is always override existing file.

You may consider to use SftpFileTemplate.exists() before sending an MV command.

We indeed may consider to improve AbstractRemoteFileOutboundGateway.mv() logic to use provided FileExistsMode. Feel free to raise a GH issue and contribute such a feature.

0
Tomek Niemczak On

enter image description hereGood to know, it depends on version. On screenshot: spring-integration-sftp:6.1.3 sshd-sftp:2.9.2

I updated app to uses spring-integration-sftp:6.2.0 sshd-sftp:2.11.0 and works well.

rename method implementation in 6.2.0 enter image description here