diff --git a/index.coffee b/index.coffee index 8c4502e..18a4fda 100644 --- a/index.coffee +++ b/index.coffee @@ -87,6 +87,10 @@ module.exports = configFileName: type: 'string' default: '.remote-sync.json' + concurrentTransports: + type: 'integer' + default: '1' + description: 'How many transfers in process at the same time' activate: (state) -> projectDict = {} diff --git a/lib/UploadListener.coffee b/lib/UploadListener.coffee index de76688..0aa140d 100644 --- a/lib/UploadListener.coffee +++ b/lib/UploadListener.coffee @@ -13,7 +13,7 @@ class UploadListener handleAction: (localFilePath, transport, action) -> if not @queue async = require "async" if not async - @queue = async.queue(@processFile.bind(@), 1) + @queue = async.queue(@processFile.bind(@), atom.config.get('remote-sync-pro.concurrentTransports')) if @queue.length() diff --git a/lib/transports/FtpTransport.coffee b/lib/transports/FtpTransport.coffee index 38244c5..8784c8e 100644 --- a/lib/transports/FtpTransport.coffee +++ b/lib/transports/FtpTransport.coffee @@ -117,16 +117,24 @@ class FtpTransport {hostname, port, username, password, secure} = @settings if @connection - return callback null, @connection - - @logger.log "Connecting: #{username}@#{hostname}:#{port}" + connection = @connection + if @isConnected + return callback null, connection + else + connection.on "ready", -> + callback null, connection + return FtpConnection = require "ftp" if not FtpConnection - connection = new FtpConnection + @connection = connection + @isConnected = false + + @logger.log "Connecting: #{username}@#{hostname}:#{port}" wasReady = false - connection.on "ready", -> + connection.on "ready", => + @isConnected = true wasReady = true callback null, connection @@ -136,6 +144,7 @@ class FtpTransport @connection = null connection.on "end", => + @isConnected = false @connection = null connection.connect @@ -144,5 +153,3 @@ class FtpTransport user: username password: password secure: secure - - @connection = connection diff --git a/lib/transports/ScpTransport.coffee b/lib/transports/ScpTransport.coffee index 95e1d4f..1c9fb16 100644 --- a/lib/transports/ScpTransport.coffee +++ b/lib/transports/ScpTransport.coffee @@ -134,16 +134,24 @@ class ScpTransport {hostname, port, username, password, keyfile, useAgent, passphrase, readyTimeout} = @settings if @connection - return callback null, @connection - - @logger.log "Connecting: #{username}@#{hostname}:#{port}" + connection = @connection + if @isConnected + return callback null, connection + else + connection.on "ready", -> + callback null, connection + return SSHConnection = require "ssh2" if not SSHConnection - connection = new SSHConnection + @connection = connection + @isConnected = false + + @logger.log "Connecting: #{username}@#{hostname}:#{port}" wasReady = false - connection.on "ready", -> + connection.on "ready", => + @isConnected = true wasReady = true callback null, connection @@ -153,6 +161,7 @@ class ScpTransport @connection = null connection.on "end", => + @isConnected = false @connection = null if keyfile @@ -185,5 +194,3 @@ class ScpTransport passphrase: passphrase readyTimeout: readyTimeout agent: agent - - @connection = connection