This is in grouper_v2_4_0_api_patch_81 and newer.

Configure sftp sites to be able to get/put sftp files.

Configure

grouper.properties

##################################
## SFTP sites
## the "configId" will be the identifier used in code to pull up that site, dont put special chars in it
## you shouldnt have the same host and username in two different configIds since its essentially the primary key
## e.g. if you sftp server is "depot.school.edu", the configId could be "depot"
##################################


general config

# SFTP needs to use some files to connect.  Keep this in a dir that only the tomcat user can read
# otherwise it will use the tmp dir configured in grouper.properties.
# {valueType: "string"}
grouperSftpBaseDirName = 

config per site

# host: e.g. some.server.com
# {valueType: "string", regex: "^grouperSftp\\.site\\.[a-zA-Z0-9._-]+\\.host$", required: true}
# grouperSftp.site.configId.host = 

# user: e.g. someuser
# {valueType: "string", regex: "^grouperSftp\\.site\\.[a-zA-Z0-9._-]+\\.user$", required: true}
# grouperSftp.site.configId.user = 

# you can encrypt the private key to connect with.  if its more than 4k encrypted, then take it in chunks and they will be concatenated
# and use _0, _1, _2, etc.  Note, replace newlines with $newline$ so it fits in a textfield
# {valueType: "password", sensitive: true, regex: "^grouperSftp\\.site\\.[a-zA-Z0-9._-]+\\.secret\\.privateKey_[0-9]$"}
# grouperSftp.site.configId.secret.privateKey_0 = 

# private key passphrase
# {valueType: "password", sensitive: true, regex: "^grouperSftp\\.site\\.[a-zA-Z0-9._-]+\\.secret\\.privateKeyPassphrase$"}
# grouperSftp.site.configId.secret.privateKeyPassphrase = 

# password if not using private key
# {valueType: "password", sensitive: true, regex: "^grouperSftp\\.site\\.[a-zA-Z0-9._-]+\\.password$"}
# grouperSftp.site.configId.password = 

# connect to the host, and copy the known_hosts entry for the host to connect to
# e.g. host.whatever ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA3B00cx5W9KPSjzik3E
# {valueType: "string", regex: "^grouperSftp\\.site\\.[a-zA-Z0-9._-]+\\.knownHostsEntry$"}
# grouperSftp.site.configId.knownHostsEntry = 

# if any temporary files (e.g. private key and known hosts) should be deleted after session, default true
# {valueType: "boolean", regex: "^grouperSftp\\.site\\.[a-zA-Z0-9._-]+\\.deleteTempFilesAfterSession$"}
# grouperSftp.site.configId.deleteTempFilesAfterSession = true

# timeout in millis defaults to 10000
# {valueType: "integer", regex: "^grouperSftp\\.site\\.[a-zA-Z0-9._-]+\\.timeoutMillis$"}
# grouperSftp.site.configId.timeoutMillis = 


Logging

log4j.properties

log4j.logger.edu.internet2.middleware.grouper.app.file.GrouperSftp = DEBUG

Sample log message

2019-11-23 21:18:20,117: [main] DEBUG GrouperSftp.callback(255) -  - configId: depot, grouperSftpDirName: C:\Users\mchyzer\AppData\Local\Temp\grouperSftp\sftpSession_2019_11_23__21_18_16_795_UDMNM4A9, keyFileSize: 3246, host: depot.school.edu, knownHost: depot.school.edu ssh-rsa AA********c2E..., knownHostsContainsHost: true, user: myUser, passphrase?: <none>, password?: <none>, timeoutMillis: 10000, sendFileLocal_0: C:\Users\mchyzer\AppData\Local\Temp\MyFile.csv, sendFileRemote_0: /data01/dept/app/SomeFile.csv, deleteDir: true, tookMillis: 3321


Using the API

You can make individual calls or use a callback to do multiple calls more efficiently

Individual calls

GrouperSftp.sendFile("depot", new File("d:/temp/temp/MyFile.csv"), "/data01/isc/bplogix/MyFile.csv");

System.out.println(GrouperUtil.toStringForLog(GrouperSftp.listFiles("depot", "/data01/isc/bplogix/")));

System.out.println(GrouperSftp.existsFile("depot", "/data01/isc/bplogix/MyFile.csv"));

GrouperSftp.copyFile("depot", "/data01/isc/bplogix/MyFile.csv", "/data01/isc/bplogix/MyFile2.csv");

GrouperSftp.moveFile("depot", "/data01/isc/bplogix/MyFile.csv", "/data01/isc/bplogix/MyFile3.csv");

GrouperSftp.receiveFile("depot", "/data01/isc/bplogix/MyFile3.csv", new File("d:/temp/temp/MyFile2.csv"));

GrouperSftp.deleteFile("depot", "/data01/isc/bplogix/MyFile3.csv");




Multiple calls in callback

    GrouperSftp.callback("depot", new GrouperSftpCallback() {
      
      public Object callback(GrouperSftpSession grouperSftpSession) {
        grouperSftpSession.sendFile(new File("d:/temp/temp/PennUsers.csv"), "/data01/isc/bplogix/PennUsers.csv");
        grouperSftpSession.deleteFile("/data01/isc/bplogix/whatever.txt");
        return null;
      }
    });



  • No labels