Some content on this site is available only to logged-in subscribers. Contact Us for information on becoming a subscriber.

InSource.Solutions | InSource Training | InSource Client Portal
InSource Solutions Logo
Log In Sign Up
InSource.Solutions InSource Training InSource Client Portal Log In Sign Up
  • Home
  • AVEVA Application Server
  • AVEVA Application Server Tech Notes

TN AppSvr299 A Simple FTP Upload Script for Wonderware Application Server

Last updated: March 3rd, 2025

Description

  • Author: Brian Schneider
  • Published: March 3rd, 2025

Details:

Description

This article from InSource shows how to script a FTP Upload using Wonderware Application Server

  • Author: Bruce Telford
  • Published: 05/31/2018
  • Applies to: Wonderware Application Server

Details

Objective

To upload a file from a local location to an FTP site. For example, some customers don’t allow direct access to their ERP systems, but would rather manage the integration themselves for a variety of reasons (support and political purposes, etc.). This script, in Application Server, will transfer a file to a remote FTP site.

Prerequisites

To function, the following minimum information available, and if possible tested /validated with a FTP Client Software package something like Filezilla. Replace the following content with valid information “<all content between and including braces>”

FTP Server/IP: "ftp.<domain>";
User ID: "<userid>";
Password: "<password>";
Target Location: "/inbound/";

Attributes

CmdSendFTP (Boolean)

FeedbackMsg (string)

FilePath (string)

FileName (string)

… all variable below can be done this way if needed

Script Code (Async):

Me. CmdSendFTP = false; '' Resets Send FTP trigger
Me.FeedbackMsg = ""; '' Initialize message string
'Variables for all FTP information
Dim sFTPServer as string;
Dim sFTPUserID as string;
Dim sFTPPassword as string;
Dim sFTPLocation as string;
sFTPServer = "ftp.<domain>"; '' or IP Address
sFTPUserID = "<userid>";
sFTPPassword = "<password>";
sFTPLocation = "/inbound/"; '' include "/" unless added in URI string below
'Variables for File information
Dim sFullFileName as string;
Dim sFilePath as string;
Dim sFileName as string;
sFilePath = Me.FilePath;
sFileName = Me.FileName;
sFullFileName = sFilePath + sFileName;
'If file exists proceed
If System.IO.File.Exists(sFullFileName) Then
'Build URI for FTP Server and Upload File
Dim uFtpTarget = new System.Uri("ftp://" + sFTPServer + sFTPLocation + sFileName);
'LogMessage("DEBUG: *** " + uFtpTarget + " ***");
try
'Create Request to Upload File
Dim objFtpRequest as System.Net.FtpWebRequest;
objFtpRequest = System.Net.WebRequest.Create(uFtpTarget);
objFtpRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
'Specify Username & Password
objFtpRequest.Credentials = new System.Net.NetworkCredential (sFTPUserID, sFTPPassword);
'Locate File and Store it in a Byte Array
Dim btFile[10240] As System.Byte;
btFile = System.IO.File.ReadAllBytes(sFullFileName);
'Get the File
Dim objStrFile As System.IO.Stream;
objStrFile = objFtpRequest.GetRequestStream();
'Upload Each Byte
objStrFile.Write(btFile, 0, btFile.Length);
'Close the file
objStrFile.Close();
'Free up the Memory
objStrFile.Dispose();
catch
Me.FeedbackMsg = "FTP Try...Catch Error: " + error.Message.ToString();
LogError("ERROR: *** " + Me.FeedbackMsg + " ***");
LogError(error.InnerException.Message.ToString());
endtry;
Else
Me.FeedbackMsg = "INFO: File does not exist at location -:- File: " + sFullFileName ;
LogError("ERROR: *** " + Me.FeedbackMsg + " ***");
Endif;

 

ftp upload wonderware script
Give feedback about this article

Recommended articles

TN - 1240 Creating a Watchlist Using an Import File

Read More

How to receive group emails

Read More
Support Icon

CONTACT SUPPORT

How to reach us

10800 Midlothian Turnpike Tpke, Suite 209, Richmond, VA 23235

1.877.INSOURCE

Technical Support - 1.888.691.3858

Contact Us

  • InSource Solutions
  • InSource Training
  • InSource Client Portal
  • Log In
InSource Solutions Logo

© 2025 InSource Solutions. All Rights Reserved.

Knowledge Base Software powered by Helpjuice

Expand