Search code examples
springfilespring-integrationnas

Spring - extract files from NAS folder


I'm trying to pull some files from a NAS (Linux) to local machine by using Spring.

I'd like not to use SFTP session in Spring even it works... in fact I used to pull files from an sftp server but due to some reason now the only resource I have is this NAS.

Is there any way to get it worked ? Or I have to write my own class?


Solution

  • Quoting from here java read file from network device:

    The simplest way to do this would be to read it using regular file paths.

    On Windows:

    new File("\\\\server\\path\\to\\file.txt")
    // (double-backslashes required for backslashes in path)
    

    On Unix:

    First mount the share using Samba (SMB, NFS or whatever other protocol) to some location like /mnt/network. Then you can use:

    new File("/mnt/network/path/to/file.txt")
    

    Once you have the File object you can use FileInputStream, FileReader or whatever else you want to read the file in.

    As far as you are able to mount the remote shared dir to the local filesystem you can easily start to use regular Spring Integration:

    <int-file:inbound-channel-adapter channel="files"
                    directory="/mnt/network/path/to/">
        <int:poller fixed-delay="10000"/>
    </int-file:inbound-channel-adapter>