ActiveState Community

Save to remote server - macro

Posted by xxcezz on 2009-09-12 16:09
OS: All / Any

This macro will allow you to save the current working file to a remote server already specified under Edit->Preferences->Servers. This is a per-project remote file save macro that relies on the 'Active Project' so you will have to have the project active u wish to do uploads for. Maybe later I will make it not require the project be 'Active'. I needed this feature as I came from phpED and it had the CTRL+SHIFT+S that would save the file to the server. SPEEDS up work!

Based off 'komoku' (http://community.activestate.com/xpi/komoku) extension that had a 'remoteSave' function that did not work for me at all. made it work outside of being an extension.

This package has two macros, 'uploadsettings' and 'uploadToSite'.

'uploadsettings' > drag into your project root edit and change the settings to point to your local directory and your remote server location.
NOTE!! DO NOT use the hostname in the main_FTPdir, just use the 'name' of the 'Server' you created in preferences.

'uploadToSite' > this is the magic script. double click or assign a different key binding than CTRL+SHIFT+S. Will take the current document you are working on and upload it to the server specified in 'uploadsettings'. REQUIRES that it be in the 'Active Project'

http://www.cloudtaco.com

AttachmentSize
RemoteSave.kpz2.4 KB

julesbl | Thu, 2009-10-15 07:50

Hi

This looks realy useful, almost got it working.

Got the error function actually stopping the attempt at saving now, but cant seem to get it to find the url.
I am using an sftp remote account called w34u, have tried various uri's
sftp://w34u/etc.
and
ssh://w34u/etc.

None of them work. Anybody got any ideas?

See code below.

remoteSave();
function remoteSave(){
    var fileURI = ko.views.manager.currentView.document.file.URI;
    var flag=true;
    if(true){
        upPath = ko.projects.manager.currentProject.getChildWithTypeAndStringAttribute('macro', 'name', 'uploadsettings', true);
        if (upPath){
            eval(upPath.value);
            var baseFTPdir = main_FTPdir;
            var patt   = new RegExp(local_URIdir + "(.*)");
            var resultUri = patt.exec(fileURI);
//                alert(baseFTPdir + resultUri[1])    
            if(jokSave(baseFTPdir + resultUri[1])){
                ko.statusBar.AddMessage("Save " + baseFTPdir+resultUri[1] + " successful..." , "UpLoad", 500, true);
            }
        }
    }
}
function jokSave(uri){
    curDoc = ko.views.manager.currentView.document;

    try {
        window.setCursor("wait");
        var newDocument = ko.views.manager.currentView.__docsvc.createDocumentFromURI(uri);
            newDocument.new_line_endings  =  curDoc.new_line_endings;
            newDocument.setBufferAndEncoding(curDoc.buffer,
                                             curDoc.encoding.python_encoding_name);
            newDocument.save(false);
        window.setCursor("auto");
        return true;
    } catch (ex) {
        window.setCursor("auto");
        alert( 'Permission denied or wrong path \n('+ uri +' '+ ex);
        return false;
    }
}

xxcezz | Thu, 2009-10-15 09:16

What is the exact error?

The sftp:// would be the correct protocol uri. However I believe it may not have been clear that the path after the name of the server MUST be the full path including any 'default path' u may have set in the server config.

Because the URI sftp://w34u/ does not dump you into the specified server 'default path'.
If you have the default path set to /www/
and you want to save to /www/etc/ then it would look like

sftp://w34u/www/etc/

julesbl | Mon, 2009-10-19 03:07

Hi
Got the path working, needed to use ssh, now get

Permission denied or wrong path
ssh://w34u/w34u.com/public/ssp/index.php
Error: File is not writeable

the permissions are fine for this user so I assume it is something to do with save being not the prefered way of doing this now, there are apparently asynchronous commands to do this, unfortunately none of these commands are detailed in the komodo api documentation so I assume they are a part of some other system which has been extended.
Anybody know where I can find the full api documentation?

Jules