Skip to content

Instantly share code, notes, and snippets.

@onedanshow
Last active September 25, 2015 07:48
Show Gist options
  • Save onedanshow/887636 to your computer and use it in GitHub Desktop.
Save onedanshow/887636 to your computer and use it in GitHub Desktop.
Server-Side Actionscript to Sync Folders: After a user records his webcam video through Flash Media Server (FMS), this server-side actionscript can be used to compare two directories and sync the local recordings to the network location. Assumes you have a 'local_repo' and 'network_repo' virtual
application.onDisconnect = function(client) {
trace("\nLOG: Syncing webcam files to data storage...");
var localDir = new File("local_repo");
var backupDir = new File("network_repo");
if(localDir.isDirectory && backupDir.isDirectory) {
var lFiles = localDir.list();
var iFiles = networkDir.list();
for(var i = 0; i < lFiles.length; i++) {
var found = false;
var lFile = lFiles[i];
var lPath = lFile.name; // ex: "/local_repo/1234_12341234.flv"
var lName = lPath.slice(lPath.lastIndexOf('/'),lPath.length); // ex: "/1234_12341234.flv"
//trace("Checking for "+lName);
for(var j = 0; j < iFiles.length; j++) {
var iPath = iFiles[j].name;
var iName = iPath.slice(iPath.lastIndexOf('/'),iPath.length);
if(lName == iName) {
found = true;
break;
}
}
if(!found) {
trace("Unsynced: "+lName+" (created: "+lFile.creationTime+")")
if(!lFile.isOpen && lFile.copyTo("/network_repo"+lName)) {
// remove the file?
trace("SUCCESS: Copied file to Network Repo.")
} else {
trace("ERROR: Could not copy "+lName+" to Network repo. Whether it is open or not: "+lFile.isOpen)
}
}
}
}
else {
trace("ERROR: Could not access the directories");
trace("Local Directory: "+localDir.isDirectory);
trace("Network Directory: "+backupDir.isDirectory);
}
trace("LOG: Syncing completed.")
};
application.onStatus = function(info) {
switch(info.level) {
case "error":
trace("\nERROR STATUS: "+info.code)
break;
case "warning":
trace("\nWARNING STATUS: "+info.code)
break;
default:
trace("\nDEFAULT STATUS: "+info.code)
}
trace("Details: "+info.details)
trace("Details: "+info.description);
trace("Filename: "+info.filename)
trace("LineNo: "+info.lineno)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment