Home Download Buy Blog Forum Support

WinSCP integration

WinSCP integration

Postby gpfsmurf on Thu Oct 22, 2009 12:11 am

I'm working on a WinSCP integration (useful to me mostly because of the winscp stored sessions)
I'll welcome any help, for development or testing.

I adapted sublimator's QuickBrowseDir plugin; the lazy loading of files is an obvious advantage to FTP browsing.
EDIT: You'll need AAALoadFirstExtensions for this to work. If it's not really needed, I'll remove the dependency later.

BitBucket homepage: http://bitbucket.org/gpfsmurf/winscp/wiki/Home

How to use:
The plugin assumes WinSCP is installed in c:\program files\winscp3, if not, change the paths at the beginning of the file.
By default, F12 is used to pop up the session list.
So press F12, it shows a list of winscp's stored sessions. Select one, it'll connect (that'll take a few seconds) and then you can browse the server.
Choosing a folder will browse to that folder.
Choosing a file will download and open it in Sublime.
You can press F12 again to choose another file.
Whenever you save a file, it's uploaded back to the server automatically.
Choosing ":close session:" or closing Sublime will close the current FTP connection. Pressing F12 after that will let you connect to a new server.

Be careful, I only did limited testing.


Question:
In case the user never chooses ":close session:", I'd like to close the session and do some cleanup in the event that sublime is closed. What's the best way to do that?

EDIT: changed How to use section
Last edited by gpfsmurf on Thu Oct 29, 2009 6:34 am, edited 1 time in total.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: WinSCP integration

Postby elrom on Fri Oct 23, 2009 2:11 am

sublimator wrote:Portable version of Sublime


I'm guessing you meant winscp.
elrom
 
Posts: 10
Joined: Sun Oct 18, 2009 4:08 am

Re: WinSCP integration

Postby gpfsmurf on Fri Oct 23, 2009 8:28 pm

re: AAALoadFirstExtensions dependency: sounds good, although personnally I would still have both

atexit.register: thanks, it seems to work well, I don't know if it works if sublime crashes though. You can always kill the winscp.com processes through the task manager, but I'd like to avoid that.

I use WinSCP 4.2.3, by default it installs to "C:\Program Files\WinSCP3". Maybe it's because I upgraded from WinSCP 3.xx in the past?

There's an option in WinSCP to store the settings in an INI file instead of the registry. You can find it in Preferences -> Storage -> INI file.
I suppose it shouldn't be too hard to add some code to search the registry as well.

re: winscp.com: I'm not sure how to make it work with winscp.exe. It spawns a new console window. According to http://winscp.net/eng/docs/executables, you can copy winscp.com to a portable installation and it should work.


The package is now on BitBucket: http://bitbucket.org/gpfsmurf/winscp/wiki/Home
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: WinSCP integration

Postby gpfsmurf on Fri Oct 23, 2009 11:59 pm

Downloading files works now, just select a file, it'll download it in a temp folder and open it in sublime.

When you close the connection, all of the temp files will be deleted.

Changes are not propagated back to the server for now; I'm debating using "put" or "keepuptodate".

* put uploads files on demand, i.e. with a keybinding (or an onSave event?)
* keepuptodate will update the file on the server each time it is saved locally, just like it works in WinSCP's remote editing feature
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: WinSCP integration

Postby EJ12N on Sat Oct 24, 2009 2:53 pm

gpfsmurf wrote:Downloading files works now, just select a file, it'll download it in a temp folder and open it in sublime.

When you close the connection, all of the temp files will be deleted.

Changes are not propagated back to the server for now; I'm debating using "put" or "keepuptodate".

* put uploads files on demand, i.e. with a keybinding (or an onSave event?)
* keepuptodate will update the file on the server each time it is saved locally, just like it works in WinSCP's remote editing feature


* keepuptodate ftw :)
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: WinSCP integration

Postby gpfsmurf on Thu Oct 29, 2009 2:21 am

Unfortunately I'll have to go with the 'put' route.

The problem with 'keepuptodate' is that it doesn't return until we're finished. So you can only edit one file at a time (actually, you can edit more than one file at a time, as long as they are in the same remote directory.) If you want to edit two files in two different folders at the same time, you're out of luck.

Fortunately, Sublime has 'onSave' events, so we can still achieve the same functionality using 'put'.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: WinSCP integration

Postby gpfsmurf on Thu Oct 29, 2009 6:31 am

Made a few important changes:
- file changes are now uploaded to server
- if INI file is not found, registry is used instead
and smaller changes:
- reconnects on session timeout
- better handling of different FTP LIST output

So the base functionnality is there. You can connect to a server, get a file, modify it, and each time you save it, it'll be uploaded back automatically.

I've only done VERY LIMITED testing so be careful.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: WinSCP integration

Postby gpfsmurf on Sat Oct 31, 2009 12:04 am

Changes: It will now ask for a password if the password is not stored instead of hanging.

Question: does anyone know how to kill a subprocess (in windows, with Python 2.5)?

subprocess.Popen.terminate() doesn't exist prior to 2.6.

I tried this (found on the web) but it doesn't seem to work:
Code: Select all
    import ctypes
    PROCESS_TERMINATE = 1
    handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, pid)
    ctypes.windll.kernel32.TerminateProcess(handle, -1)
    ctypes.windll.kernel32.CloseHandle(handle)
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: WinSCP integration

Postby myel on Sat Oct 31, 2009 9:31 pm

this is really great great stuff!

i havent really tested this plugin but so far it looks good. although i work with svn most of the time, there are older projects with are edited live (with winscp), so this plugin comes in very handy.

one feature that would be very cool: set a subfolder of the remote server as an project mount point, so we can use sublimes project management features...

ps: it is ingenious that it relies on winscp which is by far the best sftp client for windows that i know of.
myel
 
Posts: 88
Joined: Sat Mar 22, 2008 11:26 pm

Re: WinSCP integration

Postby gpfsmurf on Sun Nov 01, 2009 12:51 am

myel wrote:one feature that would be very cool: set a subfolder of the remote server as an project mount point, so we can use sublimes project management features...

Sounds cool... I'll try to do something like that after the basic functionnality is properly tested


@ sublimator: thanks!
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Next

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 2 guests