You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dmitry (Jira)" <ji...@apache.org> on 2022/10/26 21:59:00 UTC

[jira] [Updated] (VFS-826) SFTP file get content issue for some servers

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

Dmitry updated VFS-826:
-----------------------
    Description: 
Some SFTP servers does not allow multiple channels open at same time,

but SftpFileObject always open two if no hacks applied - at first just creates channel, then creates new channel to fetch type. 

Thus it is not possible to read the file in straightforward manner.

Possible solution is to move file type check on top, so underlying code of getType will 'park' channel and then it will be reused.
{code:java}
protected InputStream doGetInputStream(int bufferSize) throws Exception {
    synchronized((SftpFileSystem)this.getAbstractFileSystem()) {
        ChannelSftp channel = ((SftpFileSystem)this.getAbstractFileSystem()).getChannel();

        InputStream inputStream;
        try {
            if (!this.getType().hasContent()) {
                throw new FileSystemException("vfs.provider/read-not-file.error", this.getName());
            }

            inputStream = channel.get(this.relPath);
        } catch (SftpException var7) {
            if (var7.id == 2) {
                throw new FileNotFoundException(this.getName());
            }

            throw new FileSystemException(var7);
        }

        return new SftpInputStream(channel, inputStream, bufferSize);
    }
} {code}

  was:
Some SFTP servers does not allow multiple channels open at same time,

but SftpFileObject always open two if no hacks applied - at first just creates channel, then creates new channel to fetch type. 

Possible solution is to move file type check on top, so underlying code of getType will 'park' channel and then it will be reused.
{code:java}
protected InputStream doGetInputStream(int bufferSize) throws Exception {
    synchronized((SftpFileSystem)this.getAbstractFileSystem()) {
        ChannelSftp channel = ((SftpFileSystem)this.getAbstractFileSystem()).getChannel();

        InputStream inputStream;
        try {
            if (!this.getType().hasContent()) {
                throw new FileSystemException("vfs.provider/read-not-file.error", this.getName());
            }

            inputStream = channel.get(this.relPath);
        } catch (SftpException var7) {
            if (var7.id == 2) {
                throw new FileNotFoundException(this.getName());
            }

            throw new FileSystemException(var7);
        }

        return new SftpInputStream(channel, inputStream, bufferSize);
    }
} {code}


> SFTP file get content issue for some servers
> --------------------------------------------
>
>                 Key: VFS-826
>                 URL: https://issues.apache.org/jira/browse/VFS-826
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.9.0
>            Reporter: Dmitry
>            Priority: Major
>
> Some SFTP servers does not allow multiple channels open at same time,
> but SftpFileObject always open two if no hacks applied - at first just creates channel, then creates new channel to fetch type. 
> Thus it is not possible to read the file in straightforward manner.
> Possible solution is to move file type check on top, so underlying code of getType will 'park' channel and then it will be reused.
> {code:java}
> protected InputStream doGetInputStream(int bufferSize) throws Exception {
>     synchronized((SftpFileSystem)this.getAbstractFileSystem()) {
>         ChannelSftp channel = ((SftpFileSystem)this.getAbstractFileSystem()).getChannel();
>         InputStream inputStream;
>         try {
>             if (!this.getType().hasContent()) {
>                 throw new FileSystemException("vfs.provider/read-not-file.error", this.getName());
>             }
>             inputStream = channel.get(this.relPath);
>         } catch (SftpException var7) {
>             if (var7.id == 2) {
>                 throw new FileNotFoundException(this.getName());
>             }
>             throw new FileSystemException(var7);
>         }
>         return new SftpInputStream(channel, inputStream, bufferSize);
>     }
> } {code}



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