In addition to using the File Transfer Execution Method, file transfers can also be performed using the JAMS PowerShell module. The module supports transfers in the following forms: FTP, FTPS, and SFTP. Before a connection can be made, 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 be made. The following example demonstrates the format for establishing an FTP connection:
[Establishing a Connection]
Connect-JFTP -Credential $userCredentials -Name YourFileServerName
The other two transfer methods follow the same format, but "Connect-JFTP" would be replaced with "Connect-JFTPS" or "Connect-JSFTP". The following examples are the same for any of the three transfer methods. Once a connection is made, you can retrieve or send files to the server.
[Sending and Retrieving Files]
The format for sending a file is as follows:
Send-JFSItem -Name C:\MyFile.txt -Destination /RemoteFolderPath/MyFile.txt
The format for retrieving a file is very similar:
Receive-JFSItem -Name /RemoteFolderPath/MyFile.txt -Destination C:\MyFile.txt
To view files in a directory, use the cmdlet "Get-JFSChildItem":
Get-JFSChildItem -Path /RemoteFolderPath
Another option is to view details about a specific item using "Get-JFSItem":
Get-JFSItem -Path /RemoteFolderPath/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 you 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 /RemoteFolderPath
[Renaming and 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 /RemoteFolderPath/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]
After 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 the PowerShell Execution Method. Below is a simple example of how to use these cmdlets to perform an FTP transfer:
# # Get the credentials for the FTP user # $userCredentials = Get-JAMSCredential JAMSFTPUser # # Connect to the FTP Server # Connect-JFTP -Credential $userCredentials -Name FTPServerName # # Send a file # Send-JFSItem -Name C:\Logs\Audit_Data.txt -Destination /RemoteFolderPath/Audit_Data.txt # # Retrieve a file # Receive-JFSItem -Name /RemoteFolderPath/Audit_Data.txt -Destination C:\Logs\Audit_Data.txt # # Disconnect from the server # Disconnect-JFS
Is there a way for a FTP job to overwrite and replace the file if it already exists?
This command seems to be case-sensitive. How can we change that?