You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Simon Alexander (Jira)" <ji...@apache.org> on 2023/01/19 09:27:00 UTC

[jira] [Updated] (VFS-830) SFTP - moveto() throws FileSystemException: Could not set the last modified timestamp

     [ https://issues.apache.org/jira/browse/VFS-830?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Simon Alexander updated VFS-830:
--------------------------------
    Description: 
I am uploading a file via a temp file, by using the following code:

 
{code:java}
FileSystemOptions opts = createDefaultOptions();
BytesIdentityInfo identityInfo = new BytesIdentityInfo(sshKey.getBytes(), null);
SftpFileSystemConfigBuilder.getInstance().setIdentityProvider(opts, identityInfo);
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
SftpFileSystemConfigBuilder.getInstance().setSessionTimeout(opts, Duration.ofMillis(10000)); 
SftpFileSystemConfigBuilder.getInstance().setDisableDetectExecChannel(opts, true);

// Create temp remote file object
String tempFilePath = remoteFolder + FilePathSeparator + tempFileName;
tempFileObject = remoteManager.resolveFile(new URI("sftp",server.getServerInfo(),server.HostName,server.Port,tempFilePath,null,null).toString(), opts);
tempFileObject.copyFrom(sourceFileObject, Selectors.SELECT_SELF);
// rename to the correct name tempFileObject.moveTo(remoteFileObject);} {code}
In this code, `sourceFileObject` is on a remote linux server; and `tempFileObject` and `remoteFileObject` are on the AWS SFTP Transfer server.

 

When I run this code, the creation of the temp file runs successfully (using `copyFrom()`), but then the `moveTo()` call fails with the following exception:

*java.io.IOException: copyFileBetweenServersUsingTempFile() - Could not set the last modified timestamp of "testRemoteFileName.txt"*

 

I was trying to understand why the moveTo() call would fail in this way, so I started digging into the Apache code. As far as I can see, the call to `setLastModifiedTime()` only happens if the code thinks that the source and target filesystems are different - see [commons-vfs/AbstractFileObject.java at 83514069293cbf80644f1d47dd3eceaaf4e6954b · apache/commons-vfs · GitHub|https://github.com/apache/commons-vfs/blob/83514069293cbf80644f1d47dd3eceaaf4e6954b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java#L1726]
{code:java}
if (fileSystem == newfile.getFileSystem()) // canRenameTo()
{
 ...
}
else
{
 ...
destFile.getContent().setLastModifiedTime(this.getContent().getLastModifiedTime());
} {code}
The issue, I think, is the `==` in the canRenameTo() method - because I am actually moving from the temp file to the final file on the same file system, which means this should be returning true not false, right? presumably we should be using `.equals()` here, and overriding equals in the appropriate type of `FileSystem` object?

  was:
I am uploading a file via a temp file, by using the following code:

 
{code:java}
FileSystemOptions opts = createDefaultOptions();
BytesIdentityInfo identityInfo = new BytesIdentityInfo(sshKey.getBytes(), null);
SftpFileSystemConfigBuilder.getInstance().setIdentityProvider(opts, identityInfo);
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
SftpFileSystemConfigBuilder.getInstance().setSessionTimeout(opts, Duration.ofMillis(10000)); 
SftpFileSystemConfigBuilder.getInstance().setDisableDetectExecChannel(opts, true);

// Create temp remote file object
String tempFilePath = remoteFolder + FilePathSeparator + tempFileName;
tempFileObject = remoteManager.resolveFile(new URI("sftp",server.getServerInfo(),server.HostName,server.Port,tempFilePath,null,null).toString(), opts);
tempFileObject.copyFrom(sourceFileObject, Selectors.SELECT_SELF);
// rename to the correct name tempFileObject.moveTo(remoteFileObject);} {code}
In this code, `sourceFileObject` is on a remote linux server; and `tempFileObject` and `remoteFileObject` are on the AWS SFTP Transfer server.

 

When I run this code, the creation of the temp file runs successfully (using `copyFrom()`), but then the `moveTo()` call fails with the following exception:

*java.io.IOException: copyFileBetweenServersUsingTempFile() - Could not set the last modified timestamp of "testRemoteFileName.txt"*

 

I was trying to understand why the moveTo() call would fail in this way, so I started digging into the Apache code. As far as I can see, the call to `setLastModifiedTime()` only happens if the code thinks that the source and target filesystems are different:

[AbstractFileObject Source|[commons-vfs/AbstractFileObject.java at 83514069293cbf80644f1d47dd3eceaaf4e6954b · apache/commons-vfs · GitHub|https://github.com/apache/commons-vfs/blob/83514069293cbf80644f1d47dd3eceaaf4e6954b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java#L1726]]
{code:java}
if (fileSystem == newfile.getFileSystem()) // canRenameTo()
{
 ...
}
else
{
 ...
destFile.getContent().setLastModifiedTime(this.getContent().getLastModifiedTime());
} {code}
The issue, I think, is the `==` in the canRenameTo() method - because I am actually moving from the temp file to the final file on the same file system, which means this should be returning true not false, right? presumably we should be using `.equals()` here, and overriding equals in the appropriate type of `FileSystem` object?


> SFTP - moveto() throws FileSystemException: Could not set the last modified timestamp
> -------------------------------------------------------------------------------------
>
>                 Key: VFS-830
>                 URL: https://issues.apache.org/jira/browse/VFS-830
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.9.0
>         Environment: RHEL Linux server connecting to AWS Transfer SFTP Server
>            Reporter: Simon Alexander
>            Priority: Minor
>
> I am uploading a file via a temp file, by using the following code:
>  
> {code:java}
> FileSystemOptions opts = createDefaultOptions();
> BytesIdentityInfo identityInfo = new BytesIdentityInfo(sshKey.getBytes(), null);
> SftpFileSystemConfigBuilder.getInstance().setIdentityProvider(opts, identityInfo);
> SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
> SftpFileSystemConfigBuilder.getInstance().setSessionTimeout(opts, Duration.ofMillis(10000)); 
> SftpFileSystemConfigBuilder.getInstance().setDisableDetectExecChannel(opts, true);
> // Create temp remote file object
> String tempFilePath = remoteFolder + FilePathSeparator + tempFileName;
> tempFileObject = remoteManager.resolveFile(new URI("sftp",server.getServerInfo(),server.HostName,server.Port,tempFilePath,null,null).toString(), opts);
> tempFileObject.copyFrom(sourceFileObject, Selectors.SELECT_SELF);
> // rename to the correct name tempFileObject.moveTo(remoteFileObject);} {code}
> In this code, `sourceFileObject` is on a remote linux server; and `tempFileObject` and `remoteFileObject` are on the AWS SFTP Transfer server.
>  
> When I run this code, the creation of the temp file runs successfully (using `copyFrom()`), but then the `moveTo()` call fails with the following exception:
> *java.io.IOException: copyFileBetweenServersUsingTempFile() - Could not set the last modified timestamp of "testRemoteFileName.txt"*
>  
> I was trying to understand why the moveTo() call would fail in this way, so I started digging into the Apache code. As far as I can see, the call to `setLastModifiedTime()` only happens if the code thinks that the source and target filesystems are different - see [commons-vfs/AbstractFileObject.java at 83514069293cbf80644f1d47dd3eceaaf4e6954b · apache/commons-vfs · GitHub|https://github.com/apache/commons-vfs/blob/83514069293cbf80644f1d47dd3eceaaf4e6954b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java#L1726]
> {code:java}
> if (fileSystem == newfile.getFileSystem()) // canRenameTo()
> {
>  ...
> }
> else
> {
>  ...
> destFile.getContent().setLastModifiedTime(this.getContent().getLastModifiedTime());
> } {code}
> The issue, I think, is the `==` in the canRenameTo() method - because I am actually moving from the temp file to the final file on the same file system, which means this should be returning true not false, right? presumably we should be using `.equals()` here, and overriding equals in the appropriate type of `FileSystem` object?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)