@@ -395,35 +395,58 @@ func (m *Manager) Download(env *config.Environment, host, remotePath, localDir s
395395 return cmd .Run ()
396396}
397397
398- // sshCommandOpts returns SSH options for external commands (rsync, ssh)
399- func (m * Manager ) sshCommandOpts (keyPath string , port int ) string {
400- opts := fmt .Sprintf ("ssh -i %s -p %d" , keyPath , port )
401- if m .InsecureHostKey {
402- opts += " -o StrictHostKeyChecking=no"
403- }
404- return opts
405- }
406-
407- // UploadDir transfers a local directory to a remote server
398+ // UploadDir transfers a local directory to a remote server via tar + SCP
408399func (m * Manager ) UploadDir (env * config.Environment , host , localDir , remoteDir string ) error {
409400 if m .DryRun {
410401 logger .Info ("[DRY-RUN] Would upload directory %s to %s:%s" , localDir , host , remoteDir )
411402 return nil
412403 }
413404
414405 expandedKey := expandPath (env .SSHKeyPath )
415- sshOpts := m .sshCommandOpts (expandedKey , env .SSHPort )
416406
417- cmd := exec .Command ("rsync" , "-avz" , "--progress" ,
418- "-e" , sshOpts ,
419- localDir + "/" ,
420- fmt .Sprintf ("%s@%s:%s/" , env .SSHUser , host , remoteDir ),
421- )
422- cmd .Stdout = os .Stdout
423- cmd .Stderr = os .Stderr
407+ // Create temp tar.gz
408+ tmpFile , err := os .CreateTemp ("" , "tow-upload-*.tar.gz" )
409+ if err != nil {
410+ return fmt .Errorf ("creating temp file: %w" , err )
411+ }
412+ tmpPath := tmpFile .Name ()
413+ tmpFile .Close ()
414+ defer os .Remove (tmpPath )
424415
425- logger .Debug ("[%s] rsync %s → %s" , host , localDir , remoteDir )
426- return cmd .Run ()
416+ // tar the directory
417+ tarCmd := exec .Command ("tar" , "czf" , tmpPath , "-C" , localDir , "." )
418+ if err := tarCmd .Run (); err != nil {
419+ return fmt .Errorf ("tar %s: %w" , localDir , err )
420+ }
421+
422+ // SCP to remote
423+ remoteTmp := fmt .Sprintf ("/tmp/tow-upload-%d.tar.gz" , time .Now ().UnixNano ())
424+ scpArgs := []string {"-i" , expandedKey , "-P" , fmt .Sprintf ("%d" , env .SSHPort )}
425+ if m .InsecureHostKey {
426+ scpArgs = append (scpArgs , "-o" , "StrictHostKeyChecking=no" )
427+ }
428+ scpArgs = append (scpArgs , tmpPath , fmt .Sprintf ("%s@%s:%s" , env .SSHUser , host , remoteTmp ))
429+
430+ scpCmd := exec .Command ("scp" , scpArgs ... )
431+ if err := scpCmd .Run (); err != nil {
432+ return fmt .Errorf ("scp to %s: %w" , host , err )
433+ }
434+
435+ // Extract on remote
436+ extractCmd := fmt .Sprintf ("mkdir -p %s && tar xzf %s -C %s && rm -f %s" , remoteDir , remoteTmp , remoteDir , remoteTmp )
437+ sshArgs := []string {"-i" , expandedKey , "-p" , fmt .Sprintf ("%d" , env .SSHPort )}
438+ if m .InsecureHostKey {
439+ sshArgs = append (sshArgs , "-o" , "StrictHostKeyChecking=no" )
440+ }
441+ sshArgs = append (sshArgs , fmt .Sprintf ("%s@%s" , env .SSHUser , host ), extractCmd )
442+
443+ sshCmd := exec .Command ("ssh" , sshArgs ... )
444+ if err := sshCmd .Run (); err != nil {
445+ return fmt .Errorf ("extract on %s: %w" , host , err )
446+ }
447+
448+ logger .Debug ("[%s] uploaded dir %s → %s" , host , localDir , remoteDir )
449+ return nil
427450}
428451
429452// InteractiveLogin opens an interactive SSH session
0 commit comments