Sublime Forum

WinSCP integration

#1

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

0 Likes

FTP Client for Sublime
Feature Request: Integrated ftp/ssh/sftp support
Feature Request: Integrated ftp/ssh/sftp support
#2

I’m guessing you meant winscp.

0 Likes

#3

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

0 Likes

#4

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
0 Likes

#5

[quote=“gpfsmurf”]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[/quote]

  • keepuptodate ftw :smile:

0 Likes

#6

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’.

0 Likes

#7

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.

0 Likes

#8

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:

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)

0 Likes

#9

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.

0 Likes

#10

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

@ sublimator: thanks!

0 Likes

#11

@ myel: could you open a new issue on the bitbucket page so I don’t forget? If possible with some details about how you would like this to work exactly… We could have a ‘remoteDir’ option in the local project, or do you want a copy of the project on the server? etc

On the page: Issues -> New Issue -> Create new -> put some info and set Type to enhancement

Thanks!

0 Likes

#12

hm,

i nearly got it working myself…

i just added a recursive function to iterate though all subdirectories ( please bear with me, first time i do something with python ):

    def get_folder_list(self, folder, wait=1):
        files = self.recursive_get_folder_list( folder )
        # rewrite / to \ so we can use the sublime directory filter stuff
        renamed = ]
        for singleFile in files:
            renamed += [singleFile.replace( "/", "\\")]
        yield renamed
        
    def recursive_get_folder_list(self, folder, wait=1):
        entries = self.winscp.listDirectory(folder)
        files = ]
        dirs = ]

        for line in entries:
            try:
                info = parse.parse_ftp_list_line(line.rstrip())
            except:
                continue

            if not info:
                continue

            name = info.name
            isDir = info.try_cwd
            if name in '.', '..']: continue
            if isDir:
                dirs += [folder + '/' + name]
            else:
                files += [folder + '/' + name]
        
        # recursivly iterate through subdirectories
        for subDir in dirs:
            files.extend( self.recursive_get_folder_list( subDir ) )
           
        # yielding so scheduled.threaded works
        return sorted(files)    

i have to replace / with \ so i can use sublimes directory file stugg ("\foo index.html"), but it breaks everything else :smile:.

is there any way that i can get / working?

0 Likes

#13

python has a lib for that: os

look more on os.path.normpath(path), see docs.python.org/library/os.path.html

0 Likes

#14

I’m trying to get this plugin to work but can’t seem to. I have AAA and WinSCP installed. I can use WinSCP just fine. When I open Sublime though and hit F12 nothing happens.

Any ideas what I’m doing wrong?

Thanks.

EDIT: All is well now. My problem was fixed in the latest push.

0 Likes

#15

http://pastebin.com/bKhmYRwi

when i try to go inside a subfolder under the host, i got this error

0 Likes

#16

Does your FTP have file names that have special characters or non-english characters (i.e. ‘ö’)?

0 Likes

#17

:unamused: yes

0 Likes