ooverwriting files

Please post here if you have problems in using Wing FTP Server.

ooverwriting files

Postby marklib » Fri Feb 18, 2011 5:33 pm

Hi,

Are there server side measures possible to avoid overwriting existing files and possibly enforce an automatic renaming?

Thanks in advance
marklib
 
posts 1
 
joined Fri Feb 18, 2011 5:29 pm

Re: ooverwriting files

Postby FTP » Sat Feb 19, 2011 2:55 am

Do you mean in Web Client? I think current version can't handle it, but if is possible to implement, we will consider to add such feature in the future version.
FTP
Site Admin
 
posts 1243
 
joined Tue Sep 29, 2009 6:09 am

Re: ooverwriting files

Postby FTP » Sat Feb 19, 2011 7:46 am

Hi,again

Enforcement an automatic renaming instead of overwriting file is possible, but you can only rename the existed file automatically, you just need to modify the following files:

1. webclient/rename.html, replace line 5-6 into:
Code: Select all
local oldname = _POST["oldname"] or _GET["oldname"] or nil
local newname = _POST["newname"] or _GET["newname"] or nil



2. webclient/main.html, replace the function "function checkOverwrite(filename,totalfiles)" into:
Code: Select all
function checkOverwrite(filename,totalfiles)
{
   try
   {
      totalfiles = parseInt(totalfiles);
   }
   catch(e)
   {
      totalfiles = 1;
   }

   var overwrite = false;
   var upFilename = htmlencode(filename);
   var listtableRows = $("listtable").tBodies[0].rows;
   for (var i=0; i < listtableRows.length; i++)
   {
      if(upFilename == listtableRows[i].cells[0].getAttribute("name"))
      {
         overwrite = true;
         break;
      }
   }

   if(overwrite == true)
   {
      var bConfirm = false;
      if(auto_overwrite == true)
         bConfirm = true;
      else
         bConfirm = confirm("<%=LANG['overwrite_confirm']%>");

      if(bConfirm == false)
      {
         return "0";
      }
      else
      {
         var nowtime = new Date().getTime();
         var tmpname = upFilename;
         var newname = "";
         if(tmpname.lastIndexOf(".") != -1)
            newname = tmpname.substr(0,tmpname.lastIndexOf(".")) + "_" + nowtime + tmpname.substr(tmpname.lastIndexOf("."));
         else
            newname = tmpname + "_" + nowtime;

         var httpreqObj = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();
         var httpreqURL = "rename.html?oldname="+urlEncode(upFilename)+"&newname="+urlEncode(newname);
         httpreqObj.open("GET",httpreqURL,false);
         httpreqObj.send("");

         if(auto_overwrite == true)
            return "1";
      }
   }

   if(totalfiles > 1 && overwrite == true && confirm("<%=LANG['str_auto_overwrite']%>") == true)
      auto_overwrite = true;

   return "1";
}



3. webclient/main.html, replace the function "function uploadStart()" into:
Code: Select all
function uploadStart()
{
   if(uploading == false)
   {
      if($("filename").value == "")
      {
         alert("<%=LANG['error_no_uploadfile']%>");
         return false;
      }
      else
      {
         upload_filename = "";
         var tmpname = $("filename").value;
         if(tmpname.lastIndexOf("\\") != -1)
            upload_file = tmpname.substr(tmpname.lastIndexOf("\\")+1);
         else if(tmpname.lastIndexOf("\/") != -1)
            upload_file = tmpname.substr(tmpname.lastIndexOf("\/")+1);
         else
            upload_file = tmpname;
      }

      var overwrite = false;
      var upFilename = htmlencode(upload_file);
      var listtableRows = $("listtable").tBodies[0].rows;
      for (var i=0; i < listtableRows.length; i++)
      {
         if(upFilename == listtableRows[i].cells[0].getAttribute("name"))
         {
            overwrite = true;
            break;
         }
      }

      if(overwrite == true)
      {
         if(confirm("<%=LANG['overwrite_confirm']%>") == false)
         {
            return false;
         }
         else
         {
            var nowtime = new Date().getTime();
            var tmpname = upFilename;
            var newname = "";
            if(tmpname.lastIndexOf(".") != -1)
               newname = tmpname.substr(0,tmpname.lastIndexOf(".")) + "_" + nowtime + tmpname.substr(tmpname.lastIndexOf("."));
            else
               newname = tmpname + "_" + nowtime;

            var httpreqObj = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();
            var httpreqURL = "rename.html?oldname="+urlEncode(upFilename)+"&newname="+urlEncode(newname);
            httpreqObj.open("GET",httpreqURL,false);
            httpreqObj.send("");
         }
      }

      uploading = true;
      $("uploadingDiv").style.display = "";
      $("uploadingDiv").innerHTML = "<%=LANG['upload_ready']%><img src='images/loading.gif'>";
      $("uploadingDiv").focus();

      setTimeout("idleupload()",3000);
       d = new Date();
      start_time = d.getTime();
      last_uploadsize = 0;
      last_lefttime = -1;
      return true;
   }
   else
   {
      return false;
   }
}
FTP
Site Admin
 
posts 1243
 
joined Tue Sep 29, 2009 6:09 am


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest