Does Plant Scada support FTP functionality ?

Can Plant Scada support FTP Functionality ?

Parents
  • Since it is no longer built in, you can use a 3rd party tool, or the Windows FTP command line tool. Here's a script I wrote years ago to do an FTP upload using the command line. It's kind of a pain because you have to write a FTP command script to a text file, then run FTP.exe and tell it to run the script, then read back the log file it creates to tell if it was successful.

    // Function:     FtpUpload
    //
    // Description:  Uploads a file to an FTP server
    //
    // Revision:     1.00  4/29/04  Eric Black    Original
    //
    // Arguments:    sURL         URL of the FTP server (e.g. ftp.myserver.com or localhost or 192.168.1.1)
    //               sUser        FTP server login user name
    //               sPassword    FTP server login password
    //               sLocalFile   Path and filename to upload (can use path substitution)
    //               sRemotePath  FTP server folder to upload to (e.g. Reports\Current). Default is "." for the default folder
    //
    // Return Value: 0 if successful, otherwise a Citect error code is returned
    //
    // Notes:        1. This is a blocking function
    //               2. If the upload fails, check [Data]:FtpLog.txt for errors before calling FTPUpload again
    //                  or the log will be overwritten.
    //               3. If FtpUpload returns 1340 (timeout), but the upload eventually finishes successfully you may need to increase
    //                  the UPLOAD_TIMEOUT_SEC value (default is 5min)
    //               4. If this function is called from multiple threads, they will get queued up and only 1 will
    //                  run at a time.
    //               5. The sRemotePath may be case sensitive. It may also require either '/' or '\' to separate folder names. If
    //                  the path is invalid the file will upload to the default folder.
    //               6. The Citect IDC FTP Server does not support receiving files at this time (Citect 5.50)
    //
    // Example Command:  FTPUpload("ftp.widgets.com", "scadauser", "scadapwd", "[data]:dailyreport.htm", "SCADA/Reports");
    //
    INT
    FUNCTION
    FtpUpload(STRING sURL, STRING sUser, STRING sPassword, STRING sLocalFile, STRING sRemotePath = ".")
    
    	// Local Constants
    	STRING SCRIPT_FILE = "[Data]:FtpScript.txt";
    	STRING LOG_FILE = "[Data]:FtpLog.txt";
    	STRING SUCCESS_RESULT_CODE = "226";
    	INT    UPLOAD_TIMEOUT_SEC = 300;
    	
    	// Local variables
    	INT    hScriptFile = -1;
    	INT    hLogFile = -1;
    	INT    hFTPWindow = -1;
    	INT    iUploadStartTime;
    	STRING sText;
    	STRING sComSpec;
    
    	ErrSet(1);
    
    	IF NOT FileExist(sLocalFile) THEN
    		RETURN 261;  // File does not exist
    	END
    
    	sComSpec = GetEnv("ComSpec"); // Get path & filename of DOS command interpreter
    		
    	EnterCriticalSection("FTPUpload");
    
    	// Create a new FTP script file with the specified settings
    
    	FileDelete(SCRIPT_FILE);
    	hScriptFile = FileOpen(SCRIPT_FILE, "a");
    	
    	IF hScriptFile = -1 THEN
    		LeaveCriticalSection("FTPUpload");
    		RETURN 264; // Cannot write to script file
    	END
    		
    	FileWriteLn(hScriptFile, "open " + sURL);
    	FileWriteLn(hScriptFile, sUser);
    	FileWriteLn(hScriptFile, sPassword);
    	FileWriteLn(hScriptFile, "binary");
    	FileWriteLn(hScriptFile, "cd " + sRemotePath);
    	FileWriteLn(hScriptFile, "put ^"" + PathToStr(sLocalFile) + "^"");
    	FileWriteLn(hScriptFile, "bye");
    	FileClose(hScriptFile);
    
    	FileDelete(LOG_FILE);
    
    	// Run the script by executing ftp.exe -s:"<script file>" > "<log file>"
    		// The '>' sign redirects the output from the screen to the log file
    	// "s are necessary in case there are spaces in the paths/filenames
    
    	Exec(sComSpec + " /c ftp.exe -s:^"" + PathToStr(SCRIPT_FILE) + "^" > ^"" + PathToStr(LOG_FILE) + "^"", 6);
    
    	iUploadStartTime = TimeCurrent();
    
    	SleepMS(500);
    
    	// Hide the command window
    
    	hFTPWindow = WndFind(sComSpec);  // NT/2000/XP window title
    
    	IF hFTPWindow = 0 THEN
    		hFTPWindow = WndFind("FTP"); // Windows 98 window title
    	END
    	
    	IF hFTPWindow > 0 THEN
    		WndShow(hFTPWindow, 0);   // Hide the FTP command window
    	END
    	
    	// Watch for upload to complete, fail, or time out
    
    	WHILE TRUE DO
    
    		IF FileExist(LOG_FILE) THEN
    
    			IF hLogFile = -1 THEN
    				hLogFile = FileOpen(LOG_FILE, "r");
    				IF hLogFile = -1 THEN
    					LeaveCriticalSection("FTPUpload");
    					RETURN 262; // Cannot open log file
    				END
    			END   
    
    			FileSeek(hLogFile, 0);
    	
    			WHILE NOT FileEOF(hLogFile) DO
    				
    				sText = FileReadLn(hLogFile);
    			
    				IF StrLeft(sText, StrLength(SUCCESS_RESULT_CODE)) = SUCCESS_RESULT_CODE THEN
    					FileClose(hLogFile);
    					LeaveCriticalSection("FTPUpload");
    					RETURN 0;  // Success!
    				ELSE
    					IF StrRight(sText, 3) = "bye" THEN
    						LeaveCriticalSection("FTPUpload");
    						FileClose(hLogFile);
    						RETURN 264;  // Cannot write to FTP server. Check ftp log
    					END
    				END
    			END
    		END
    		
    		IF TimeCurrent() - iUploadStartTime > UPLOAD_TIMEOUT_SEC THEN
    			FileClose(hLogFile);
    			LeaveCriticalSection("FTPUpload");
    			RETURN 1340; // Timeout. Upload may complete eventually
    		END
    
    		Sleep(1);
    	END
    END
    
Reply
  • Since it is no longer built in, you can use a 3rd party tool, or the Windows FTP command line tool. Here's a script I wrote years ago to do an FTP upload using the command line. It's kind of a pain because you have to write a FTP command script to a text file, then run FTP.exe and tell it to run the script, then read back the log file it creates to tell if it was successful.

    // Function:     FtpUpload
    //
    // Description:  Uploads a file to an FTP server
    //
    // Revision:     1.00  4/29/04  Eric Black    Original
    //
    // Arguments:    sURL         URL of the FTP server (e.g. ftp.myserver.com or localhost or 192.168.1.1)
    //               sUser        FTP server login user name
    //               sPassword    FTP server login password
    //               sLocalFile   Path and filename to upload (can use path substitution)
    //               sRemotePath  FTP server folder to upload to (e.g. Reports\Current). Default is "." for the default folder
    //
    // Return Value: 0 if successful, otherwise a Citect error code is returned
    //
    // Notes:        1. This is a blocking function
    //               2. If the upload fails, check [Data]:FtpLog.txt for errors before calling FTPUpload again
    //                  or the log will be overwritten.
    //               3. If FtpUpload returns 1340 (timeout), but the upload eventually finishes successfully you may need to increase
    //                  the UPLOAD_TIMEOUT_SEC value (default is 5min)
    //               4. If this function is called from multiple threads, they will get queued up and only 1 will
    //                  run at a time.
    //               5. The sRemotePath may be case sensitive. It may also require either '/' or '\' to separate folder names. If
    //                  the path is invalid the file will upload to the default folder.
    //               6. The Citect IDC FTP Server does not support receiving files at this time (Citect 5.50)
    //
    // Example Command:  FTPUpload("ftp.widgets.com", "scadauser", "scadapwd", "[data]:dailyreport.htm", "SCADA/Reports");
    //
    INT
    FUNCTION
    FtpUpload(STRING sURL, STRING sUser, STRING sPassword, STRING sLocalFile, STRING sRemotePath = ".")
    
    	// Local Constants
    	STRING SCRIPT_FILE = "[Data]:FtpScript.txt";
    	STRING LOG_FILE = "[Data]:FtpLog.txt";
    	STRING SUCCESS_RESULT_CODE = "226";
    	INT    UPLOAD_TIMEOUT_SEC = 300;
    	
    	// Local variables
    	INT    hScriptFile = -1;
    	INT    hLogFile = -1;
    	INT    hFTPWindow = -1;
    	INT    iUploadStartTime;
    	STRING sText;
    	STRING sComSpec;
    
    	ErrSet(1);
    
    	IF NOT FileExist(sLocalFile) THEN
    		RETURN 261;  // File does not exist
    	END
    
    	sComSpec = GetEnv("ComSpec"); // Get path & filename of DOS command interpreter
    		
    	EnterCriticalSection("FTPUpload");
    
    	// Create a new FTP script file with the specified settings
    
    	FileDelete(SCRIPT_FILE);
    	hScriptFile = FileOpen(SCRIPT_FILE, "a");
    	
    	IF hScriptFile = -1 THEN
    		LeaveCriticalSection("FTPUpload");
    		RETURN 264; // Cannot write to script file
    	END
    		
    	FileWriteLn(hScriptFile, "open " + sURL);
    	FileWriteLn(hScriptFile, sUser);
    	FileWriteLn(hScriptFile, sPassword);
    	FileWriteLn(hScriptFile, "binary");
    	FileWriteLn(hScriptFile, "cd " + sRemotePath);
    	FileWriteLn(hScriptFile, "put ^"" + PathToStr(sLocalFile) + "^"");
    	FileWriteLn(hScriptFile, "bye");
    	FileClose(hScriptFile);
    
    	FileDelete(LOG_FILE);
    
    	// Run the script by executing ftp.exe -s:"<script file>" > "<log file>"
    		// The '>' sign redirects the output from the screen to the log file
    	// "s are necessary in case there are spaces in the paths/filenames
    
    	Exec(sComSpec + " /c ftp.exe -s:^"" + PathToStr(SCRIPT_FILE) + "^" > ^"" + PathToStr(LOG_FILE) + "^"", 6);
    
    	iUploadStartTime = TimeCurrent();
    
    	SleepMS(500);
    
    	// Hide the command window
    
    	hFTPWindow = WndFind(sComSpec);  // NT/2000/XP window title
    
    	IF hFTPWindow = 0 THEN
    		hFTPWindow = WndFind("FTP"); // Windows 98 window title
    	END
    	
    	IF hFTPWindow > 0 THEN
    		WndShow(hFTPWindow, 0);   // Hide the FTP command window
    	END
    	
    	// Watch for upload to complete, fail, or time out
    
    	WHILE TRUE DO
    
    		IF FileExist(LOG_FILE) THEN
    
    			IF hLogFile = -1 THEN
    				hLogFile = FileOpen(LOG_FILE, "r");
    				IF hLogFile = -1 THEN
    					LeaveCriticalSection("FTPUpload");
    					RETURN 262; // Cannot open log file
    				END
    			END   
    
    			FileSeek(hLogFile, 0);
    	
    			WHILE NOT FileEOF(hLogFile) DO
    				
    				sText = FileReadLn(hLogFile);
    			
    				IF StrLeft(sText, StrLength(SUCCESS_RESULT_CODE)) = SUCCESS_RESULT_CODE THEN
    					FileClose(hLogFile);
    					LeaveCriticalSection("FTPUpload");
    					RETURN 0;  // Success!
    				ELSE
    					IF StrRight(sText, 3) = "bye" THEN
    						LeaveCriticalSection("FTPUpload");
    						FileClose(hLogFile);
    						RETURN 264;  // Cannot write to FTP server. Check ftp log
    					END
    				END
    			END
    		END
    		
    		IF TimeCurrent() - iUploadStartTime > UPLOAD_TIMEOUT_SEC THEN
    			FileClose(hLogFile);
    			LeaveCriticalSection("FTPUpload");
    			RETURN 1340; // Timeout. Upload may complete eventually
    		END
    
    		Sleep(1);
    	END
    END
    
Children
No Data