Skip to content

Commit fd9af4b

Browse files
Merge pull request #742 from thheinen/theinen/fix-upload
Fix upload to support individual files
2 parents b855af4 + e093420 commit fd9af4b

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

lib/train/plugins/base_connection.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,25 @@ def file(path, *args)
162162
@cache[:file][path] ||= file_via_connection(path, *args)
163163
end
164164

165-
# Uploads local files or directories to remote host.
165+
# Uploads local files to remote host.
166166
#
167-
# @param locals [Array<String>] paths to local files or directories
167+
# @param locals [String, Array<String>] path to local files
168168
# @param remote [String] path to remote destination
169169
# @raise [TransportFailed] if the files could not all be uploaded
170170
# successfully, which may vary by implementation
171171
def upload(locals, remote)
172-
unless file(remote).directory?
173-
raise TransportError, "#{self.class} expects remote directory as second upload parameter"
172+
remote_directory = file(remote).directory?
173+
174+
if locals.is_a?(Array) && !remote_directory
175+
raise Train::TransportError, "#{self.class} expects remote directory as second upload parameter for multi-file uploads"
174176
end
175177

176178
Array(locals).each do |local|
177-
new_content = File.read(local)
178-
remote_file = File.join(remote, File.basename(local))
179+
remote_file = remote_directory ? File.join(remote, File.basename(local)) : remote
179180

180181
logger.debug("Attempting to upload '#{local}' as file #{remote_file}")
181182

182-
file(remote_file).content = new_content
183+
file(remote_file).content = File.read(local)
183184
end
184185
end
185186

0 commit comments

Comments
 (0)