Promotic
WikipediaLinkedInYoutubeTwitterFacebook

Example of file transfer by means of FTP (ActiveX)

This is an example of the transfer of files over the Intranet/Internet by the FTP protokol. Usage of the ChilkatFTP ActiveX objektu 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, 0x0);
else
{
//Change to the remote directory where the file will be uploaded.
success = oftp.ChangeRemoteDir("/FTP");
if (success != 1)
Pm.MessageBox("Warning - ChangeRemoteDir", oftp.LastErrorText, 0x0);
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, 0x0);
else
{
oftp.Disconnect();
Pm.MessageBox("Transfer file", "File Uploaded!", 0x0);
}
}
}
 
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, 0x0);
else
{
//Change to the remote directory where the file will be uploaded.
//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, 0x0);
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, 0x0);
else
{
oftp.Disconnect();
Pm.MessageBox("Transfer file", "File Download!", 0x0);
}
}
}
PROMOTIC 9.0.13 SCADA system documentation - MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice