@@ -540,72 +540,59 @@ export class FTPUploader {
540540 }
541541 }
542542
543- // Delete obsolete files first
543+ // Delete obsolete files first (best effort, don't block upload on deletion errors)
544544 if ( toDelete . length > 0 ) {
545+ console . log ( `[FTP Incremental] 🗑️ Attempting to delete ${ toDelete . length } obsolete files...` ) ;
545546 for ( const filePath of toDelete ) {
546547 try {
547- await this . client . remove ( filePath ) ;
548+ // Use absolute remote path for deletion
549+ const remoteFilePath = this . config . remoteDir && this . config . remoteDir !== '/'
550+ ? `${ this . config . remoteDir } /${ filePath } ` . replace ( / \\ / g, '/' )
551+ : filePath . replace ( / \\ / g, '/' ) ;
552+ await this . client . remove ( remoteFilePath ) ;
548553 } catch ( err ) {
549- console . warn ( `[FTP Incremental] - Failed to delete ${ filePath } :` , err ) ;
554+ // Deletion errors are non-critical - just log and continue
555+ // The main goal is to upload new/updated files successfully
556+ console . error ( `[FTP Incremental] - ⚠️ Failed to delete ${ filePath } (non-critical):` , err ) ;
550557 }
551558 }
552559 }
553560
554561 // Track created directories to avoid repeated creation attempts
555562 const createdDirs = new Set < string > ( ) ;
556-
563+
557564 for ( const filePath of toUpload ) {
558565 const localFilePath = path . join ( localDir , filePath ) ;
559- const remoteFilePath = filePath ;
560-
566+ // Use absolute remote path: base directory + relative path
567+ const remoteFilePath = this . config . remoteDir && this . config . remoteDir !== '/'
568+ ? `${ this . config . remoteDir } /${ filePath } ` . replace ( / \\ / g, '/' )
569+ : filePath . replace ( / \\ / g, '/' ) ;
570+
561571 // Ensure remote directory exists
562572 const remoteDir = path . dirname ( remoteFilePath ) . replace ( / \\ / g, '/' ) ;
563573 if ( remoteDir && remoteDir !== '.' && remoteDir !== '/' ) {
564574 if ( ! createdDirs . has ( remoteDir ) ) {
565575 try {
566- // Split path and create directories one by one
567- const parts = remoteDir . split ( '/' ) . filter ( p => p ) ;
568- let currentPath = '' ;
569-
570- for ( const part of parts ) {
571- currentPath = currentPath ? `${ currentPath } /${ part } ` : part ;
572-
573- if ( ! createdDirs . has ( currentPath ) ) {
574- try {
575- // Try to create directory
576- await this . client . ensureDir ( currentPath ) ;
577- createdDirs . add ( currentPath ) ;
578- } catch ( err ) {
579- // Directory might already exist, try to cd into it
580- try {
581- await this . client . cd ( currentPath ) ;
582- createdDirs . add ( currentPath ) ;
583- } catch ( cdErr ) {
584- console . error ( `[FTP Incremental] - Failed to ensure dir ${ currentPath } :` , err ) ;
585- throw new Error ( `Cannot create or access directory: ${ currentPath } ` ) ;
586- }
587- }
588- }
589- }
590-
591- // Go back to base directory
592- if ( this . config . remoteDir && this . config . remoteDir !== '/' ) {
593- await this . client . cd ( this . config . remoteDir ) ;
594- }
595-
576+ // Use ensureDir with absolute path - it will create all parent directories
577+ await this . client . ensureDir ( remoteDir ) ;
596578 createdDirs . add ( remoteDir ) ;
597579 } catch ( err ) {
598- console . error ( `[FTP Incremental] - Failed to ensure directory ${ remoteDir } :` , err ) ;
599- throw err ;
580+ // Directory creation failed, but try to continue
581+ // The upload might still succeed if directory already exists
582+ console . error ( `[FTP Incremental] - ⚠️ Failed to ensure directory ${ remoteDir } :` , err ) ;
583+ console . error ( `[FTP Incremental] - Will attempt upload anyway...` ) ;
600584 }
601585 }
602586 }
603587
604- // Upload file
588+ // Upload file (this is the critical operation)
605589 try {
606590 await this . client . uploadFrom ( localFilePath , remoteFilePath ) ;
607591 } catch ( err ) {
608- console . error ( `[FTP Incremental] - Failed to upload ${ filePath } :` , err ) ;
592+ console . error ( `[FTP Incremental] - ❌ Upload failed for ${ filePath } :` , err ) ;
593+ console . error ( `[FTP Incremental] - Local path: ${ localFilePath } ` ) ;
594+ console . error ( `[FTP Incremental] - Remote path: ${ remoteFilePath } ` ) ;
595+ // Upload failure is critical - throw error to stop the process
609596 throw err ;
610597 }
611598 }
0 commit comments