Copy & paste for FTP paths and unexpected behaviour in general

Hello! o)

I noticed there is no "Copy Path" kind of entry on the context menu for items in a FTP location.
I wanted to fix that for myself, but I could not find a place to edit context menu entries for FTP items, is there somewhere?

Running "Clipboard COPYNAMES" in the command line worked as a workaround, but when pasting a path like ftp://mydomain//myfile.txt back into the path filed, DO does not select a file that way. It opens a window somewhere in the background like this (might take some time):
image

Removing the double slash after the domain name does not help (is this required at all?) I had a quick research, but could not find much information about it. At a first glance I would assume a single slash would be sufficient?

Additionally, DO always adds "//" to the end of the ftp location, when clicking into the path field.
I tried to wrap the ftp path into double quotes and pasting that into the path filed, but with the quotes added, the default browser opens for some reason, I can't see why that is. During all this FTP tinkering, DO crashed three times.

FTP is kind of unstable for me, some days ago I tried to access another FTP server (on my mobile phone) and DO would spam the FTP log with CWD commands. It looked like it scanned the whole file system of the phone, even if all ftp listers were closed. I was not able to find out why and I was not able to accomplish what I actually aimed for.

If I can be of help resolving any of the issues, plz let me know.
The FTP servers in questions are maintained by myself.

Thank you!

Those aren't editable, at least currently. The logic is that most commands, and all shell extension items, would not work as expected on FTP files so they're limited to a handful of things.

I'm not sure that would work with FTP sites. Even just going to an FTP URL by pasting it into the address bar is slightly iffy, unless the site uses anonymous logins or the URL includes the user name and password.

To the end, or after the domain part? It should be there after the domain part, to indicate the root folder. (Without it, at least some parts of Opus would interpret it as being relative to the site's default folder, which often isn't the root.)

Adding quotes around paths in the path field doesn't work for any type of path. (Quotes will be stripped out if you Ctrl-V paste into the path field, which happens before you push return. But if you add the quotes manually, it'll mess things up. There's no reason to ever do that.)

Please send us the crash logs.

Could be an issue with the server not responding the way Opus expects. Would be better as a separate thread, with details of the server type (so we can try to reproduce it) and what the logs showed (so we have more idea of what's happening).

1 Like

Yes, I see that. For simple things like copying the names/paths or whatever it would still be quite useful, also from some kind of style-guide or intuitive-use perspective it would make sense to not have hard coded menus, or maybe have a hard coded menu, but let users add entries (on their risk o).

My actual use case included username+pw in the path, but it seems it does not work well with filenames as last part in the path, DO expects the last part to be a folder and if it is not, it feels the need to open that dialog shown. Maybe DO could try to enter that "folder", if not successful/not present, try the parent and then (if first attempt wasn't successful), try to locate the last part which was initially passed and select the item. Yes, a first world problem, but this would help to share links to files as long as the interplanetary file system is not finished. o)

Ok, yes, I think I can understand that better now, thank you. (And yes, I meant after the domain part.)

Yes, there's no reason, I see that now. I was trying hard. o)

I did.

I will, next time. I would avoid using FTP at all, but accessing/sharing files directly from DO or for organising files on the mobile phone, it seems like the only choice. Yes, dropbox would work, but people need to install that first. And managing files on the mobile phone, not sure, every USB type of connection seems even more unstable. Kind of disappointing in such modern world, if you or somebody else has better tools at hand to move/copy files around on a phone, please let me know.

Thank you, appreciate your input!

The crash is being triggered by a script handling OnActivateTab which then runs an IsSet test on something, but I can't tell which script it is or what the IsSet test it's running is.

Any chance you could look through your installed scripts and work out which one(s) it might be so we can try to reproduce the problem?

(The crash also looks "impossible" but that's probably just the dmp being misleading, which happens sometimes as they only capture a small amount of state by default. If we can reproduce the problem we should be able to see the full/real context of what's happening and fix it.)

I searched for OnActivateTab in /scripts, opened all files in Editplus and searched each for "IsSet", only one came up "Command.Generic_SmartGetSizes.js.txt", I probably changed the name to fit my scheme, but I think its available as download here as well.
I paste the script instead of uploading it. My dev-channel browser (updated yesterday) refuses to bring up the file dialog for uploading a file, that sucks, anyway here it is.

// This is a script for written for Directory Opus v11.
// See http://www.gpsoft.com.au/redirect.asp?page=scripts for development information.

// =====================================================================================
// ======================   EVENT HANDLER: OnAfterFolderChange   =======================
//
// This script is intended as an alternative to toggling the 'Calculate folder sizes
// automatically' option in Prefs via the 'Set CALCFOLDERSIZES' command.
//
// The difference between this scripts behavior and the 'Set CALCFOLDERSIZES' command
// is that toggling the option in Prefs affects ALL listers, whereas this script is
// currently lister specific. It works as an event handler for the OnAfterFolderChange
// event, such that when a folder change is made - the script checks if a lister scoped
// variable named 'autosize' is set. If the variable is set, then the folder sizes are
// calculated automatically.
//
// Here is an example toolbar button code snippet to toggle the variable required to
// control the scripts behavior:
//
//                        @toggle:if $lst:autosize
//
//                        @ifset:$lst:autosize
//                        @set lst:autosize
//
//                        @ifset:else
//                        @set lst:autosize=true
//                        SmartGetSizes GETALL NODESELECT
//
// Both the example button code above AND this scripts main function rely on the use of
// the 'SmartGetSizes' command. That command is made available to Opus by the additional
// Script Command packaged together with this script as ScriptCommand_smartgetsizes.
// Check the Script Commands own comments and description for details on its use. It is
// inspired by code provided by Jonathan Potter to solve a user’s request for modified
// 'GetSizes' behavior. It is used in the example button code above so that when the
// button is pressed to toggle 'On' the environment variable that controls this scripts
// behavior, it also then calculates the 'current' tabs folder sizes (before any folder
// changes are made), regardless of either file/folder selection state or whether any
// selected folders have already had theirs sizes calculated or not.
//
// This version of the script currently operates on any type of folder, and does not
// currently offer the granularity of control of the actual Prefs option...


// Called by Directory Opus to initialize the script
function OnInit(initData){
  DOpus.Output("Initializing...");

  // Provide basic information about the Script
  initData.name = "Command.Generic: SmartGetSizes";
  initData.desc = "Check for lister variable on folder changes to auto-calculate folder sizes or not.";
  initData.copyright = "(c) 2014 steje, update by wowbagger";
  initData.version = "v1.0.7.b (js)";
  initData.default_enable = true;

  // Initialise the command that this script adds
  var cmd = initData.AddCommand();
  cmd.name = "SmartGetSizes";
  cmd.icon = "getsizes";
  cmd.method = "OnSmartGetSizes";
  cmd.desc = "Calculates folder sizes for selected folders on first use, then all remaining folders on " +
            "second use.\n\n" +
            "Supports the use of a GETALL option to force size calculation of all folders, ignoring folder " +
            "selection state.";
  cmd.label = "SmartGetSizes";

  // Set DEBUG flag below to true in order to enable logging messages to the Opus Output Window
  initData.config.DEBUG = false;

  return false;
}

// Implement the SmartGetSizes command
function OnSmartGetSizes(commandData)
{
  logMsg("OnSmartGetSizes running");
  SmartGetSizes();
}

function OnSourceDestChange(SourceDestData)
{
  if(SourceDestData.source )
  {
    logMsg("OnSourceDestChange running source:" + SourceDestData.source + " dest:" + SourceDestData.dest + " tab[" + SourceDestData.tab + "]:" + SourceDestData.tab.Path);
    SmartGetSizes();
  }
}

function OnActivateTab(ActivateTabData)
{
  logMsg("OnActivateTab running old:" + ActivateTabData.old.Path);
  SmartGetSizes();
}

// Called whenever the folder is changed
function OnAfterFolderChange(afterFolderChangeData)
{
  logMsg("OnAfterFolderChange running");
  SmartGetSizes();
}

function SmartGetSizes()
{
  var tab = DOpus.listers(0).activetab;
  logMsg("SmartGetSizes! tab[" + tab + "]:" + tab.path);

  var objCmd = DOpus.CreateCommand;
  if (objCmd.IsSet("$lst:autosize"))
  {
    logMsg("The 'autosize' lister variable is set!");
    objCmd.RunCommand("Set CALCFOLDERSIZES=all");
  }
  else if (objCmd.IsSet("$src:autosize"))
  {
    logMsg("The 'autosize' sourcetab variable is set!");
    objCmd.RunCommand("Set CALCFOLDERSIZES=all");
  }
  else
  {
    logMsg("The 'autosize' variable is NOT set!");
    objCmd.RunCommand("Set CALCFOLDERSIZES=off");
  }
  objCmd.UpdateToggle();
  delete objCmd;
}

function IsDebugEnabled()
{
  var objCmd = DOpus.CreateCommand;
  return (Script && Script.config.DEBUG) || objCmd.IsSet("$glob:debug");
}

// Subroutine to allow toggling of the global DEBUG variable to control whether logging is performed or not
function logMsg(message)
{
   if (IsDebugEnabled()) DOpus.Output(message);
   return;
}
///////////////////////////////////////////////////////////////////////////////
function OnAboutScript(data){ //v0.1
	var cmd = DOpus.Create.Command();
	if (!cmd.Commandlist('s').exists("ScriptWizard")){
		if (DOpus.Dlg.Request("The 'ScriptWizard' add-in has not been found.\n\n"+
"Install 'ScriptWizard' from [resource.dopus.com].\nThe add-in enables this dialog and also offers "+
"easy updating of scripts and many more.","Yes, take me there!|Cancel", "No About.. ", data.window))
		cmd.RunCommand('http://resource.dopus.com/viewtopic.php?f=35&t=23179');}
	else
		cmd.RunCommand('ScriptWizard ABOUT WIN='+data.window+' FILE="'+Script.File+'"');
}

Thanks!

I haven't been able to reproduce any crash so far, but there are some things about the script that might be making things more random than they need to be, by making it guess which file display to use in two places within SmartGetSizes.

The things that call SmartGetSizes are told which tab they are meant to be acting on, and should pass that tab object through to SmartGetSizes. Then the DOpus.listers(0).activetab line (first place it has to guess the tab to use) can be removed. The active tab should be set on the objCmd object (second place).

None of that should cause a crash, of course, but it could mean the script is acting on a tab that isn't the one that is actually triggering the event.

I'll keep it installed for a while to see if it ever goes wrong for me.

Follow-up: The script does a delete objCmd which should probably be removed. I'm not sure about JScript but the delete operator in JavaScript doesn't delete objects like the one in C++; it removes properties. I'm not sure what it would do in the context it's being used in. Maybe nothing, but maybe it's causing something strange to happen as well. In either case, it won't be doing anything good, and the object will be cleaned up automatically on the next line when the function ends.

(Sometimes variables are properties, but not ones created by var. Some good discussion and links here: pointers - Deleting Objects in JavaScript - Stack Overflow although I would skip the 1st answer as it doesn't look entirely correct, based on the others.)

1 Like