How to Use The JAMS File Transfer PowerShell Cmdlets

Follow

In addition to using the "File Transfer" execution method, file transfers can also be performed using the JAMS PowerShell Snap-In. The Snap-In supports transfers in the following forms: FTP, FTPS, and SFTP. Before a connection can be made, users must first define the credentials for the user account that will be connecting to the file server.

[Import the JAMS Module]

  

Import-Module JAMS

  

[Getting Credentials from a JAMS User]

 

$userCredentials = Get-JAMSCredential -UserName JAMSUserName -Server JAMSServerName

 

Once the credentials have been established a connection can then be made.

[Establishing a Connection]

The following example demonstrates the format for establishing an FTP connection:

Connect-JFTP -Credential $userCredentials -Name YourFileServerName

 

The other two transfer methods follow the same format except that "Connect-JFTP" would be replaced with "Connect-JFTPS" or "Connect-JSFTP". Besides that difference, the following examples are the same for any of the three transfer methods.

Once a connection is made, users can then retrieve or send files to the server. 

[Sending & Retrieving Files]

The format for sending a file is as follows:

 

Send-JFSItem -Name C:\MyFile.txt  -Destination C:\ServerDirectory\MyFile.txt

 

The format for retrieving a file is very similar:

 

Receive-JFSItem -Name C:\ServerDirectory\MyFile.txt -Destination C:\MyFile.txt

 

To view files in a directory the cmdlet "Get-JFSChildItem" can be used:

 

Get-JFSChildItem -Path C:\Logs\

 

Another option is to view details about a specific item using "Get-JFSItem":

 

Get-JFSItem -Path C:\Logs\Audit.log

 

The "Get-JFSChildItem" cmdlet is similar to the PowerShell "Get-ChildItem" cmdlet, they both return a collection of objects. 


The "Get-JFSChildItem" returns a collection of JAMSFileServerItems. Each JAMSFileServerItems describes a single file or directory that is on the file server. You can process these items using all the standard PowerShell commands, for example:

 

$fileList = Get-JFSChildItem *.txt
foreach($file in $fileList)
{
  if (($file.IsFile) -and ($file.Modified -gt $checkDate))
  {
  Receive-JFSItem $file
  }
}

 

[Directory Movement]

The "Get-JFSLocation" cmdlet enables users to determine the current path on the file server. An example of using this cmdlet might be to store the current directory in a PowerShell variable:

 

$CurrentDirectory = Get-JFSLocation

 

The "Set-JFSLocation" cmdlet allows users to change the directory on the file server and uses the format:

 

Set-JFSLocation -Location C:\NewDirectory

 

[Renaming & Removing Files]

Renaming and Removing files is also very simple. An example of renaming a file would be:

 

Rename-JFSItem -Name OriginalName.txt -NewName NewName.txt

 

While the format for removing a file is:

 

Remove-JFSItem -Path "C:\FTPNewName.txt" -Confirm:$false

 

In the example above, setting the "-Confirm" switch to false means that there should not be a verification prompt before deleting the file.

[Disconnecting]
Once the actions of the file transfer has completed users will then need to disconnect from the FTP Server to close the connection:

 

Disconnect-JFS

 

Any of these cmdlets could be issued from a PowerShell console or from a Job within JAMS that uses PowerShell as it's execution method. Below is a simple example of how to use these cmdlets to perform a FTP transfer:

 

#
# Get the credentials for our FTP user
#
$userCredentials = Get-JAMSCredential JAMSFTPUser

#
# Connect to the FTP Server
#
Connect-JFTP -Credential $userCredentials -Name FTPServer7

#
# Send a file
#
Send-JFSItem -Name C:\Logs\Audit_Data.txt -Destination C:\Common\Audit_Data.txt

#
# Retrieve a file
#
Receive-JFSItem -Name C:\Common\Audit_Data.txt -Destination C:\Logs\Audit_Data.txt

#
# Disconnect from the server
#
Disconnect-JFS

 

Have more questions? Submit a request

Comments