You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Back to the VfsCookbook

Overview

This is a basic example to use VFS to retrieve files from a remote system using the SFTP protocol. Files matching a specified regular expression are retrieved.

Example Configuration

For the purposes of this example the remote system is named "sftpremote.example.com". The files that will be retrieved are in a directory named /data/source/fires and the files are named smokeYearMoDy_wkt.txt. The data file for March 25, 2008 is named "smoke20080325_wkt.txt".

The downloaded files will be received in the local directory /extra/data/fires/smoke.

Connect to the remote sftpremote.example.com system using the login "smokey" and password "bear".

Key Concepts

Access to a remote system using SFTP uses the SSH secure shell protocols. Although the behavior is similar to FTP, it is not FTP run over a secure connection. So there are some differences between FTP and SFTP that should be noted. One of these it the lack of the FTP binary/ASCII transfer mode, in SFTP all transfers are binary as if they were executed with an "scp" (secure copy) command.

This example code uses a regular expression to match files on the remote system, so that not all of the files in the source directory are transferred.

Source Code

pom.xml Project File

This example uses Maven2. There is a pom.xml to define the project

}}}


== Code Listing ==
Content of '''{{{src/main/java/gov/noaa/eds/byExample/trySimpleVfsSftp/App.java

'''. Be sure to customize the variables near the top of the listing to match your environment if you intend to run this code. The variable to modifiy are host, user, password, remoteDir, filePatternString and localDir.

/*
 * App.java
 */

Compiling

Compile the source code with

mvn assembly:assembly

This will create an executable jar file in the standard target directory.

Running

Use a command like this to run the example

java -jar target/trySimpleVfsSftp-1.0-SNAPSHOT-jar-with-dependencies.jar

Sample Output

}}}
There should now be files matching the {{{filePatternString

in the local machine directory "/extra/data/fires/smoke".

  • No labels