Download Java CoG Kit Manual

Transcript
• Measuring performance of a file transfer
• Restarting failed transfers
Transferring files between a client and a server
As described before, GridFTP uses the GSI security mechanism. Thus, APIs
described here need security credentials in the form of an object of the class
org.ietf.jgss.GSSCredential. Please refer to the Section 4.4.5 for details about how
you can use the Java CoG Kit APIs for getting GSSCredential objects from your
GSI proxies.
/**
* Get a GSSCredential object as explained above.
*/
GSSCredential credential;
/**
* Create an instance of the GridFTPClient class.
*/
String host = "hot.mcs.anl.gov";
int port = 2811;
GridFTPClient hotClient = new GridFTPClient(host, port);
/**
* Authenticate to the server
*/
hotClient.authenticate(credential);
/**
* Set security parameters such as data channel authentication
* (defined by the GridFTP protocol) and data channel
* protection (defined by RFC 2228).
* If you do not specify these, data channels are authenticated
* by default.
*/
hotClient.setProtectionBufferSize(16384);
hotClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
hotClient.setDataChannelProtection(GridFTPSession.PROTECTION_SAFE);
/**
* Get a list of files and directories in the current directory.
* The function returns a vector of FileInfo objects.
* Each of these objects contains information about
* a remote file, such as name, size, modification time, etc.
*/
Vector fileInfoVector = hotClient.list();
/**
* Get a file from the remote server.
*/
String remoteFile1 = "testDir/getFile.txt";
File localFile1 = new File("getFile.txt");
hotClient.get(remoteFile1, localFile1);
/**
* Send a file to the remote server.
44