Update cookies preferences
Promotic

Example of file transfer by means of FTP (ActiveX)

This is an example of the transfer of files over the Internet/Intranet by the FTP protocol. Usage of the ChilkatFTP ActiveX object is presumed. It can be downloaded from the manufacturer's Web pages: http://www.chilkatsoft.com/downloads.asp. The manufacturer also offers usage examples at: http://www.example-code.com/vbscript/ftp.asp. And the interface documentation has been published at: http://www.chilkatsoft.com/refdoc/xChilkatFtpRef.html.

The technology used here is launched in the synchronous mode, therefore it will be handy to to use the PmaSequencer object for connection and file transfer in the PROMOTIC system. There is an instance created in the script to this object by the CreateObject method.

The script for sending the file to the FTP server in the passive transfer mode.:
JavaScriptVBScriptSelect and copy to clipboard

var oftp, success, localFilename, remoteFilename;

oftp = Pm.AxGetObject("new", "ChilkatFTP.ChilkatFTP.1");
oftp.Hostname = "nameserver";
oftp.Username = "*****";
oftp.Password = "*****";

// The default data transfer mode is "Active" as opposed to "Passive".
// Change it to Passive by setting the Passive property:
oftp.Passive = 1;

// Connect and login to the FTP server.
success = oftp.Connect();
if (success != 1)
{
Pm.MessageBox("Warning - Connect", oftp.LastErrorText);
}
else
{
// Change/set the FTP server folder where requested file is/will be located.
success = oftp.ChangeRemoteDir("/FTP");
if (success != 1)
{
Pm.MessageBox("Warning - ChangeRemoteDir", oftp.LastErrorText);
}
else
{
// Upload a file.
localFilename = "C:\\uplist.txt";
remoteFilename = "uplist.txt";

success = oftp.PutFile(localFilename, remoteFilename);
if (success != 1)
{
Pm.MessageBox("Warning - PutFile", oftp.LastErrorText);
}
else
{
oftp.Disconnect();
Pm.MessageBox("Transfer file", "File Uploaded!");
}
}
}


The script for downloading the file from the FTP server in the passive transfer mode.:
JavaScriptVBScriptSelect and copy to clipboard

var oftp, success, localFilename, remoteFilename;

oftp = Pm.AxGetObject("new", "ChilkatFTP.ChilkatFTP.1");
oftp.Hostname = "nameserver";
oftp.Username = "*****";
oftp.Password = "*****";

// The default data transfer mode is "Active" as opposed to "Passive".
// Change it to Passive by setting the Passive property:
oftp.Passive = 1;

// Connect and login to the FTP server.
success = oftp.Connect();
if (success != 1)
{
Pm.MessageBox("Warning - Connect", oftp.LastErrorText);
}
else
{
// Change/set the FTP server folder where requested file is/will be located.
// This step is necessary only if the file is not in the root directory for the FTP account.
success = oftp.ChangeRemoteDir("/FTP");
if (success != 1)
{
Pm.MessageBox("Warning - ChangeRemoteDir", oftp.LastErrorText);
}
else
{
// Download a file
localFilename = "C:\\uplist.txt";
remoteFilename = "uplist.txt";

success = oftp.GetFile(remoteFilename, localFilename);
if (success != 1)
{
Pm.MessageBox("Warning - GetFile", oftp.LastErrorText);
}
else
{
oftp.Disconnect();
Pm.MessageBox("Transfer file", "File Download!");
}
}
}
PROMOTIC 9.0.28 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.