Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs = require 'fs'
- Promise = require "bluebird"
- externalAccounts = require './backend/services/service.externalAccounts'
- PromiseSftp = require 'promise-sftp'
- # globalz......................................................................
- ftp = new PromiseSftp()
- #
- # expected: 450762 bytes
- # recieved: 450756 (thus corrupt and unable to gunzip)
- # discrepency amount seems to scale with file size
- #
- source = '/Managed_Refresh/Deed20160824/12043_Deed_Refresh_20160824.txt.gz'
- target = '/tmp/12043_Deed_demo.txt.gz'
- # ready the stuff..............................................................
- externalAccounts.getAccountInfo('blackknight')
- .then (accountInfo) ->
- console.log "accountInfo:\n#{JSON.stringify(accountInfo,null,2)}"
- ftp.connect
- host: accountInfo.url
- user: accountInfo.username
- password: accountInfo.password
- autoReconnect: true
- .catch (err) ->
- if err.level == 'client-authentication'
- throw new SoftFail('FTP authentication error')
- else
- throw err
- .then () ->
- # do the stuff.................................................................
- ftp.get(source)
- .then (ftpStream) -> new Promise (resolve, reject) ->
- ftpStream.on 'error', reject
- ftpStream.on 'end', resolve
- # ftpStream.on 'data', (chunk) ->
- # console.log "Received #{chunk.length} bytes of data."
- # ftpStream.on 'end', (detail) ->
- # console.log "detail:\n#{JSON.stringify(detail)}"
- # console.log "reading ended."
- # resolve(detail)
- ftpStream.pipe(fs.createWriteStream(target))
- # did the stuff................................................................
- .catch (err) ->
- console.log "Shit shit fire ze missilez..."
- throw new Error(err)
- .then () ->
- console.log "Completed."
- ftp.logout()
- process.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement