Re: AddIns-FtpUpload
var server = "ftp.myserver.net" // your FTP server name var userName = "MyUserName@telefonica.net" // your FTP account var password = "secret" // your FTP password var localFile = "C:\\NowOnAir.txt" // a temporary local file name var remoteFile = "html/NowOnAir.txt" // remote directory & file name on the web server /*************************************************************************/ var ftp; var currentSong = ""; var BLUE = 140*240*200; var RED = 255;
// The Application::Startup event is fired on startup of Raduga function Application::Startup() { Application.Console.Visible = true; DebugOutput( "FtpUpload started" ); } // The Application::Shutdown event is fired on shutdown of Raduga function Application::Shutdown() { if( ftp != null ) ftp.Close(); } // The Player::Start event is fired by Raduga whenever a new track starts function Player::Start() { var playlist = Application.Playlist; currentSong = playlist.DisplayNameOf( Player.FileName ) WriteFile(); UploadFile(); } function WriteFile() { Application.Statusbar = "Writing file " + localFile; DebugOutput( "Writing file " + localFile ); var ForWriting = 2; var FormatAscii = 0; var fso = new ActiveXObject( "Scripting.FileSystemObject" ) fso.CreateTextFile( localFile ); var file = fso.GetFile( localFile ); var ts = file.OpenAsTextStream( ForWriting, FormatAscii ); ts.WriteLine( currentSong ); ts.Close(); Application.Statusbar = ""; } function UploadFile() { Application.Statusbar = "Uploading file " + localFile + " to " + remoteFile; try { if( ftp == null ) { ftp = new ActiveXObject( "Raduga.Ftp" ); ftp.Server = server; ftp.UserName = userName; ftp.Password = password; DebugOutput( "Connecting to FTP server " + ftp.Server ); ftp.Open(); } DebugOutput( "Uploading file " + localFile + " to " + remoteFile ); ftp.PutFile( localFile, remoteFile ); } catch( error ) { HandleError( error ); ftp = null; } Application.Statusbar = ""; } function HandleError( error ) { Application.StatusBar = "FtpUpload Error: " + error.description; Application.Console.WriteLineColor( error.description, RED ); } function DebugOutput( text ) { Application.Console.WriteLineColor( text, BLUE ); }
|