@@ -138,6 +138,7 @@ def run_shell_command(
138138
139139def put_file (
140140 state , host , filename_or_io , remote_filename ,
141+ remote_temp_filename = None ,
141142 print_output = False , print_input = False ,
142143 ** kwargs # ignored (sudo/etc)
143144):
@@ -146,12 +147,12 @@ def put_file(
146147 temporary location and then uploading it into the container using ``docker cp``.
147148 '''
148149
149- fd , temp_filename = mkstemp ()
150- remote_temp_filename = state .get_temp_filename (temp_filename )
150+ fd , local_temp_filename = mkstemp ()
151+ remote_temp_filename = remote_temp_filename or state .get_temp_filename (local_temp_filename )
151152
152153 # Load our file or IO object and write it to the temporary file
153154 with get_file_io (filename_or_io ) as file_io :
154- with open (temp_filename , 'wb' ) as temp_f :
155+ with open (local_temp_filename , 'wb' ) as temp_f :
155156 data = file_io .read ()
156157
157158 if isinstance (data , six .text_type ):
@@ -160,7 +161,7 @@ def put_file(
160161 temp_f .write (data )
161162
162163 # upload file to remote server
163- ssh_status = ssh .put_file (state , host , temp_filename , remote_temp_filename )
164+ ssh_status = ssh .put_file (state , host , local_temp_filename , remote_temp_filename )
164165 if not ssh_status :
165166 raise IOError ('Failed to copy file over ssh' )
166167
@@ -180,9 +181,9 @@ def put_file(
180181 )
181182 finally :
182183 os .close (fd )
183- os .remove (temp_filename )
184+ os .remove (local_temp_filename )
184185 remote_remove (
185- state , host , temp_filename ,
186+ state , host , local_temp_filename ,
186187 print_output = print_output ,
187188 print_input = print_input ,
188189 )
@@ -200,6 +201,7 @@ def put_file(
200201
201202def get_file (
202203 state , host , remote_filename , filename_or_io ,
204+ remote_temp_filename = None ,
203205 print_output = False , print_input = False ,
204206 ** kwargs # ignored (sudo/etc)
205207):
@@ -208,14 +210,14 @@ def get_file(
208210 location and then reading that into our final file/IO object.
209211 '''
210212
211- temp_filename = state .get_temp_filename (remote_filename )
213+ remote_temp_filename = remote_temp_filename or state .get_temp_filename (remote_filename )
212214
213215 try :
214216 docker_id = host .host_data ['docker_container_id' ]
215217 docker_command = 'docker cp {0}:{1} {2}' .format (
216218 docker_id ,
217219 remote_filename ,
218- temp_filename ,
220+ remote_temp_filename ,
219221 )
220222
221223 status , _ , stderr = ssh .run_shell_command (
@@ -225,9 +227,9 @@ def get_file(
225227 print_input = print_input ,
226228 )
227229
228- ssh_status = ssh .get_file (state , host , temp_filename , filename_or_io )
230+ ssh_status = ssh .get_file (state , host , remote_temp_filename , filename_or_io )
229231 finally :
230- remote_remove (state , host , temp_filename , print_output = print_output ,
232+ remote_remove (state , host , remote_temp_filename , print_output = print_output ,
231233 print_input = print_input )
232234
233235 if not ssh_status :
0 commit comments