New UserExit for SFTP 2.0 Server and Corresponding Java Interfaces

LS/CD BEFORE

  • LS Command: This command allows you to read the files/folders from the server and provide list data to the client.
  • CD Command: This command allows you to get the details of the current path from the server.
  • Interface Name: ISftpServerUserExit_OnLSCDBeforeExecute
  • Package Name: com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nLSCDBeforeExecute
You must implement this interface to customize the LS and CD commands.
  • Method definition:
    //UserExit developer can execute Pre - LS and CD command by implementing the interface and overriding this method:
    public boolean onLSCDBeforeExecute(Map<String, Object> inargs, Map<String, Object> outargs) throws Exception;
    //UserExit developer can execute Pre - Opening Directory operation by implementing the interface and overriding this method:
    public boolean onDIROpenBeforeExecute (Map<String, Object> inargs, Map<String, Object> outargs) throws Exception;
    //UserExit developer can execute Pre - Reading Directory operation by implementing the interface and overriding this method.
    public boolean onDIRReadBeforeExecute (Map<String, Object> inargs, Map<String, Object> outargs) throws Exception;
  • The common inargs/outargs passed in the method definition are specified in section Input and output parameters details.
  • The input parameter value of KEY_COMMAND_NAME - SSH must be:
    • SSH_FXP_STAT for LS command.
    • SSH_FXP_OPENDIR for OPEN DIR command.
    • SSH_FXP_READDIR for READ DIR command.
Specific constants corresponding to LS and CD command are as follows:
  • KEY_OUTPUT_VzFSATTRIBUTES: Stores the VFSAttributes class object result.
  • KEY_READ_DIR_HANDLE: Stores the handle of open directory.
  • KEY_FILE_LIST: Stores the VFSFile class object result in list format
Following are the two classes used in LS/CD command::
  1. VFSAttributes:
    • VFSAttributes class is associated with the file operations in which the native and custom file attributes will be cached.
    • VFSAttributes class object is the response for LS (with file) or CD (with directory).
    • Custom attributes can be added as key-value pair in VFSAttributes class object corresponding to the following variable name:
      private Map<String, String> customAttributes;
    • Custom attributes on the client-side can be accessed from the VFSAttribute return object corresponding to the variable name:
      private Map<String, byte[]> extended;
    • //Sample code for setting custom attributes:
      final VfsAttributes attr = new VfsAttributes();
      attr.setDirectory(true);
      Map<String, String> customAttributes = new LinkedHashMap<String, String>();
      customAttributes.put("Volume","SGFTUY");
      customAttributes.put("Referred", "2021/10/27");
      customAttributes.put("Ext", "1");
      attr.setCustomAttributes(customAttributes);
      setDirectory(boolean): If set to true – it specifies it is a directory, else it is a file.
  2. VFSFile:
    • VFSFile class is associated with the file operations in which the filename, longName, and VFSAttributes will be cached.
    • VFSfile class object in list format is the response for LS with a directory.
    • Long name can be added in VFSfile class object corresponding to the following variable name: String longName
      Sample code for setting VFSFile:
      //Sample code for setting VFSFile[]
       Vector files = new Vector(); 
      VfsAttributes attrs = ……. //setting as shown in above code snippet
       VfsFile sftpfile = new VfsFile(<filePath/folderPath>); //Add the absolute path 
      sftpfile.setAttrs(attrs); 
      files.add(sftpfile); //Can create multiple VfsFile objects and add in the Vector 
      VfsFile[] sf = new VfsFile[files.size()]; 
      files.copyInto(sf); //final list is the response 
      outargs.put(ISftpServerUserExit_OnLSCDBeforeExecute.KEY_FILE_LIST, sf);

LS with directory will be called multiple times till the client reads all the files and directory on server (UserExit). So to terminate read dir command last, the UserExit will have to send an empty array or a null array as result. (Internally it will call EOF and it will show result till that time client received).

RM BEFORE

This command allows you to delete a file from the server.
  • Interface Name: ISftpServerUserExit_OnRMBeforeExecute
  • Package Name: com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nRMBeforeExecute
You must implement this interface to customize the the Remove file command.
  • Method definition:
    //UserExit developer can execute Pre – Remove File operation by implementing the interface 
    and overriding this method.
    public boolean onRMBeforeExecute (Map<String, Object> inargs, Map<String, Object> outargs) throws Exception;
  • The common inargs/outargs passed in the method definition are specified in section Input and output parameters details.
  • KEY_COMMAND_NAME - SSH command name input parameter value to be SSH_FXP_REMOVE.

RMDIR BEFORE

This command allows you to delete a directory from the server.
  • Interface Name: ISftpServerUserExit_OnRMDIRBeforeExecute
  • Package Name: com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nRMDIRBeforeExecute
You must implement this interface to customize the the Remove file command.
  • Method definition:
    //UserExit developer can execute Pre – Remove Directory operation by implementing 
    the interface and overriding this method.
    public boolean onRMDIRBeforeExecute (Map<String, Object> inargs, Map<String, Object> 
    outargs) throws Exception;
  • The common inargs/outargs passed in the method definition are specified in section Input and output parameters details.
  • KEY_COMMAND_NAME - SSH command name input parameter value to be SSH_FXP_RMDIR.

MKDIR BEFORE

This command allows you to create a directory on the server.
  • Interface Name: ISftpServerUserExit_OnMKDIRBeforeExecute
  • Package Name: com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nMKDIRBeforeExecute
You must implement this interface to customize the Create Directory command.
  • Method definition:
    //UserExit developer can execute Pre – Create Directory operation by implementing the 
    interface and overriding this method.
    public boolean onMKDIRBeforeExecute (Map<String, Object> inargs, Map<String, Object> 
    outargs) throws Exception;
  • The common inargs/outargs passed in the method definition are specified in section Input and output parameters details.
  • KEY_COMMAND_NAME - SSH command name input parameter value to be SSH_FXP_MKDIR.

PRE FILE UPLOAD: PUT BEFORE

This command allows putting/upload a file on the server. It executes the custom java code when the SFTP server has received the command to set a file. This allows the user to read the filename, and the user can use this to perform validations, etc.
  • Interface Name: ISftpServerUserExit_OnPUTBeforeExecute
  • Package Name:
    com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nPUTBeforeExecute (New)
    com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nPutFileBeforeExecute (Deprecated)
You must implement this interface to customize the Pre file upload operation.
  • Method definition:
    // UserExit developer can implement PUT Before command by implementing the interface and 
    overriding this method
    public boolean onPUTBeforeExecute(Map<String, Object> inargs, Map<String, Object> 
    outargs) throws Exception;
  • The common inargs/outargs passed in the method definition are specified in section Input and output parameters details.
  • Specific constants corresponding to PUT command are as follows:
    KEY_INPUT_VFSATTRIBUTES - It stores the VFSAttributes class object as input
  • KEY_COMMAND_NAME - SSH command name input parameter value to be SSH_FXP_WRITE.

POST FILE UPLOAD: PUT AFTER

This command allows putting/uploading a file on the server. It executes the custom java code when SFTP Server has received the file but has not committed into the underlying storage (mailbox or filesystem). This allows you to read the file data from an input stream. You can use this to perform operations like dumping files to some temporary location, declining the transfer based on size, performing content validation, etc.
  • Interface Name: ISftpServerUserExit_OnPUTAfterExecute
  • Package Name:
    com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nPUTAfterExecute (New)
    com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nPutFileAfterExecute (Deprecated)
You must implement this interface to customize the Post File upload command.
  • Method definition:
    // UserExit developer can implement PUT After command by implementing the interface and 
    overriding this method
    public boolean onPUTAfterExecute(Map<String, Object> inargs, Map<String, Object> outargs) throws Exception;
  • The common inargs/outargs passed in the method definition are specified in section Input and output parameters details.
  • KEY_COMMAND_N
  • AME - SSH command name input parameter value to be SSH_FXP_WRITE.

PRE FILE DOWNLOAD: GET BEFORE

This command allows getting/downloading a file from the server. It executes custom java code when the SFTP server has received a command to get a file. This will enable you to read the file data, get the size of the file, etc.
  • Interface Name: ISftpServerUserExit_onGETBeforeExecute
  • Package Name:
    com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nGETBeforeExecute (New)
    com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nGetFileBeforeExecute (Deprecated)
You must implement this interface to customize the Pre File download command.
  • Method definition:
    // UserExit developer can implement GET Before command by implementing the interface and 
    overriding this method
    public boolean onGETBeforeExecute(Map<String, Object> inargs, Map<String, Object> outargs)
     throws Exception;
  • The common inargs/outargs passed in the method definition are specified in section Input and output parameters details.
  • Specific constants corresponding to GET command are as follows:
    KEY_INPUT_VFSATTRIBUTES - It stores the VFSAttributes class object as input.
  • KEY_COMMAND_NAME - SSH command name input parameter value to be SSH_FXP_READ.

POST FILE DOWNLOAD: GET AFTER

This command allows getting/downloading a file from the server. It executes the custom java code after the SFTP server has successfully sent a file to the client as a response to the client's get command. This is used for reporting /auditing purposes. The return value of your code doesn't anyways influence the transfer of file since your code will be executed after the transfer of the file finishes.
  • Interface Name: ISftpServerUserExit_onGETAfterExecute
  • Package Name:
    com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nGETAfterExecute (New)
    com.sterlingcommerce.woodstock.userexit.services.sftpserver.interfaces.ISftpServerUserExit_O nGetFileAfterExecute (Deprecated)
You must implement this interface to customize the post file download command.
  • Method definition:
    // UserExit developer can implement GET After command by implementing the interface and 
    overriding this method
    public boolean onGETAfterExecute(Map<String, Object> inargs, Map<String, Object> outargs) 
    throws Exception;
  • The common inargs/outargs passed in the method definition are specified in section Input and output parameters details.
  • KEY_COMMAND_NAME - SSH command name input parameter value to be SSH_FXP_READ.

BASE INTERFACE :

Name: ISftpServerUserExit_OnSSHDCommandExecute

Above all interfaces extend this base interface. Here all common attributes and constants are defined.
List of common Attributes/Constants:
  • KEY_LOG_BUFFER: String
  • KEY_ERROR_BUFFER: String
  • KEY_INSTANCE_NAME: String
  • KEY_CLIENT_ADDRESS: String
  • KEY_CLIENT_PORT: String
  • KEY_SERVER_ADDRESS: String
  • KEY_SERVER_PORT: String
  • KEY_USER_ID: String
  • KEY_DOCUMENT_ID: String
  • KEY_MESSAGE_ID: String
  • KEY_FILE_SIZE: String
  • KEY_COMMAND_NAME: String
  • KEY_TRANSFER_MODE: String
  • KEY_FILE_NAME: String
  • KEY_DIR_PATH: String
  • KEY_SESSIONID: String
  • KEY_CONTENT_TYPE: String
  • KEY_ENCODING: String

The Java Interface API Documentation is available in the folder install/userexit/docs.