Upload txt File to an FTP server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hello community can someone explain how can we send a generated txt file in servicenow to an FTP server?
i already have a mid server installed and up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi Mregragui,
Critical Analysis (Best Practices): Before implementing this, be aware of two major architectural points:
Protocol Security: FTP sends credentials and data in plain text. It is highly insecure. The industry standard is SFTP (SSH). If your server supports SFTP, use that instead.
Implementation Method:
The "Official" Way: Use Integration Hub - SFTP Spoke. It has pre-built actions like "Upload File", handles credentials securely, and requires no coding. (Requires Integration Hub subscription).
The "Custom" Way: Create a custom PowerShell step on the MID Server. This is free but requires you to write and maintain the code.
Assuming you need the Custom PowerShell method (for cost reasons) and strictly FTP, here is how to build it using Flow Designer.
Step 1: Create a Custom Action
Navigate to Flow Designer > Designer.
Click New > Action. Name it "Upload to FTP".
Inputs: Define inputs for everything you need:
ftp_server (String)
username (String)
password (Password / Secure String)
file_name (String) - e.g., "report.txt"
file_content (String) - The text you generated in ServiceNow.
Step 2: Add the PowerShell Step
Click the + icon and select PowerShell.
Connection: Select "Use Connection Alias" (Best Practice) or define inline if testing.
MID Selection: Use "Select MID Server" or define capability.
Script: Paste the following script to handle the upload directly from memory (no need to save a local file on the MID first).
Powershell:
# Map Action Inputs to PowerShell Variables
$server = $inputs.ftp_server
$user = $inputs.username
$pass = $inputs.password
$fileName = $inputs.file_name
$content = $inputs.file_content
try {
# Create the URI
$uri = "ftp://$server/$fileName"
# Create WebClient Object
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user, $pass)
# Upload the String content directly as a file
$webclient.UploadString($uri, $content)
Write-Output "Success: File $fileName uploaded to $server"
}
catch {
# Catch errors and fail the action
$errorMessage = $_.Exception.Message
Write-Error "FTP Upload Failed: $errorMessage"
exit 1
}
Step 3: Define Outputs
Create an output variable (e.g., status_message).
Map the PowerShell step's output to this variable so you can see the result in your Flow.
Recommendation: If this process handles sensitive data, please advocate internally to switch the destination server to SFTP.
If this guide helps you achieve the upload, please mark it as Accepted Solution.
Best regards,
Brandão.
