cancel
Showing results for 
Search instead for 
Did you mean: 

Access file unix box using SFTP.

former_member442169
Participant
0 Kudos

Hi,

i tried acces XML file from unix box in portal application but i unable to connect .I have host name,user name,password,remote path .

I tried like

String password, String remotePath, String localPath) throws IOException {

    // we first set strict key checking off

    FileSystemOptions fsOptions = new FileSystemOptions();

    SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(

            fsOptions, "no");

    // now we create a new filesystem manager

    DefaultFileSystemManager fsManager = (DefaultFileSystemManager) VFS

            .getManager();

    // the url is of form sftp://user:pass@host/remotepath/

    String uri = "sftp://" + user + ":" + password + "@" + host

            + "/" + remotePath;

    // get file object representing the local file

    FileObject fo = fsManager.resolveFile(uri, fsOptions);

    // open input stream from the remote file

    BufferedInputStream is = new BufferedInputStream(fo.getContent()

            .getInputStream());

    // open output stream to local file

    OutputStream os = new BufferedOutputStream(new FileOutputStream(

            localPath));

    int c;

    // do copying

    while ((c = is.read()) != -1) {

        os.write(c);

    }

    os.close();

    is.close();

    // close the file object

    fo.close();

    // NOTE: if you close the file system manager, you won't be able to

    // use VFS again in the same VM. If you wish to copy multiple files,

    // make the fsManager static, initialize it once, and close just

    // before exiting the process.

    fsManager.close();

    System.out.println("Finished copying the file");

Please provide me solution.

regards,

Nari.

Accepted Solutions (0)

Answers (1)

Answers (1)

SandipAgarwalla
Active Contributor
0 Kudos

is the File Server accessible from Portal Server?

You culd look at other option of Connecting this File Server via FileSystem Repository manager in KM. In that way the File resposiroty would appear  in KM as one of the root repository. From there you can read/write files using KM APIs.