@@ -30,10 +30,10 @@ import { MonitorInProgress } from '../lib/monitorInProgress'
3030import { defaultCheckHandleRead , defaultCheckHandleWrite , defaultDoYouSupportAccess } from './lib/lib'
3131
3232import { isEqual } from '../lib/lib'
33- import { FTPClient , FTPClientBase , FTPOptions , SFTPClient } from './lib/FTPClient'
3433import { GenericFileOperationsHandler } from './lib/GenericFileOperations'
3534import { GenericFileHandler } from './lib/GenericFileHandler'
3635import { JSONWriteFilesBestEffortHandler } from './lib/json-write-file'
36+ import { createFTPClient , FTPClientBase , FTPOptions } from './lib/FTPClient/index'
3737
3838export interface Content {
3939 /** This is set when the class-instance is only going to be used for PackageContainer access.*/
@@ -221,22 +221,15 @@ export class FTPAccessorHandle<Metadata> extends GenericAccessorHandle<Metadata>
221221 const pResponse = ftp . upload ( sourceStream , fullPath )
222222
223223 pResponse
224- . then ( ( response ) => {
225- if ( response !== null ) {
226- streamWrapper . emit ( 'error' , new Error ( `FTP upload failed: ${ response } ` ) )
227- } else {
228- // All good:
229- streamWrapper . emit ( 'close' )
230- }
224+ . then ( ( ) => {
225+ streamWrapper . emit ( 'close' )
231226 } )
232227 . catch ( ( err ) => {
233- streamWrapper . emit ( 'error' , new Error ( `FTP upload threw for path "${ fullPath } ": ${ err } ` ) )
228+ const err2 = new Error ( `FTP upload threw for path "${ fullPath } ": ${ err } ` )
229+ if ( err instanceof Error ) err2 . stack += `Original stack:\n${ err . stack } `
230+ streamWrapper . emit ( 'error' , err2 )
234231 } )
235232
236- // Pipe any events from the writeStream right into the wrapper:
237- // writeStream.on('error', (err) => streamWrapper.emit('error', err))
238- // writeStream.on('close', () => streamWrapper.emit('close'))
239-
240233 return streamWrapper
241234 }
242235 async getPackageReadInfo ( ) : Promise < { readInfo : PackageReadInfo ; cancel : ( ) => void } > {
@@ -378,7 +371,13 @@ export class FTPAccessorHandle<Metadata> extends GenericAccessorHandle<Metadata>
378371 } {
379372 const serverType = this . accessor . serverType
380373 const host = this . accessor . host
381- const port = this . accessor . port ?? ( this . accessor . serverType === 'ftp' ? 21 : 22 ) // default port for FTP is 21, SFTP is 22
374+ const port =
375+ this . accessor . port ??
376+ ( this . accessor . serverType === 'ftp' || this . accessor . serverType === 'ftps'
377+ ? 21
378+ : this . accessor . serverType === 'sftp'
379+ ? 22
380+ : 990 ) // default port for FTP (and FTP + AUTH TLS) is 21, SFTP is 22, FTPS (implicit FTP over TLS/SSL) is 990
382381 const username = this . accessor . username
383382 const password = this . accessor . password
384383
@@ -411,10 +410,12 @@ export class FTPAccessorHandle<Metadata> extends GenericAccessorHandle<Metadata>
411410 // Note: this is untested:
412411 if ( ftpOptions . serverType === 'ftp' ) {
413412 url = `ftp://`
414- } else if ( ftpOptions . serverType === 'sftp ' ) {
415- url = `sftp ://`
413+ } else if ( ftpOptions . serverType === 'ftp-ssl ' ) {
414+ url = `ftps ://`
416415 } else if ( ftpOptions . serverType === 'ftps' ) {
417416 url = `ftps://`
417+ } else if ( ftpOptions . serverType === 'sftp' ) {
418+ url = `sftp://`
418419 } else {
419420 assertNever ( ftpOptions . serverType )
420421 throw new Error ( `Unsupported FTP server type "${ ftpOptions . serverType } "` )
@@ -460,13 +461,7 @@ export class FTPAccessorHandle<Metadata> extends GenericAccessorHandle<Metadata>
460461 }
461462 if ( ! cachedClient ) {
462463 // Set up a new FTP client:
463- if ( ftpOptions . serverType === 'ftp' || ftpOptions . serverType === 'ftps' ) {
464- cachedClient = new FTPClient ( this . worker . logger , options )
465- } else if ( ftpOptions . serverType === 'sftp' ) {
466- cachedClient = new SFTPClient ( this . worker . logger , options )
467- } else {
468- assertNever ( ftpOptions . serverType )
469- }
464+ cachedClient = createFTPClient ( ftpOptions . serverType , this . worker . logger , options )
470465 }
471466
472467 if ( cachedClient ) {
0 commit comments