diff --git a/lib/commands/stack/scp.js b/lib/commands/stack/scp.js index 21ce329..fbfbb26 100644 --- a/lib/commands/stack/scp.js +++ b/lib/commands/stack/scp.js @@ -309,11 +309,14 @@ class Connection { // Begin transfer. const commands = [ + // Fail on error or pipe failure. + 'set -eo pipefail', + // Start the header. `echo -n \$'\\e${ HEADER_INDICATOR };'`, // Get size using stat. - `stat -c "size=%s" ${ srcPath } | tr -d '\n'`, + `stat -c 'size=%s' ${ srcPath } | tr -d '\\n'`, // End header, start file. "echo -n $'\\a'", @@ -326,6 +329,17 @@ class Connection { ]; this.log( LEVELS.INFO, 'Sending commands' ); this.log( LEVELS.DEBUG, JSON.stringify( commands.join( '; ' ) ) ); + this.session.on( 'disconnect', () => { + if ( ! didStartFile ) { + // Some sort of error occurred, likely during stat. + // Ensure we're closed. + status.clear(); + + // Pass feedback directly to user. + this.log( LEVELS.INFO, 'Did not start file' ); + reject( new Error( header.substring( 1 ).trimEnd() ) ); + } + } ); this.session.write( commands.join( '; ' ) + '\n' ); }, 1000 ); } );