Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. fs = require 'fs'
  2. Promise = require "bluebird"
  3. externalAccounts = require './backend/services/service.externalAccounts'
  4. PromiseSftp = require 'promise-sftp'
  5.  
  6.  
  7. # globalz......................................................................
  8. ftp = new PromiseSftp()
  9. #
  10. # expected: 450762 bytes
  11. # recieved: 450756 (thus corrupt and unable to gunzip)
  12. # discrepency amount seems to scale with file size
  13. #
  14. source = '/Managed_Refresh/Deed20160824/12043_Deed_Refresh_20160824.txt.gz'
  15. target = '/tmp/12043_Deed_demo.txt.gz'
  16.  
  17.  
  18. # ready the stuff..............................................................
  19. externalAccounts.getAccountInfo('blackknight')
  20. .then (accountInfo) ->
  21. console.log "accountInfo:\n#{JSON.stringify(accountInfo,null,2)}"
  22. ftp.connect
  23. host: accountInfo.url
  24. user: accountInfo.username
  25. password: accountInfo.password
  26. autoReconnect: true
  27. .catch (err) ->
  28. if err.level == 'client-authentication'
  29. throw new SoftFail('FTP authentication error')
  30. else
  31. throw err
  32. .then () ->
  33.  
  34.  
  35. # do the stuff.................................................................
  36. ftp.get(source)
  37. .then (ftpStream) -> new Promise (resolve, reject) ->
  38.  
  39. ftpStream.on 'error', reject
  40. ftpStream.on 'end', resolve
  41.  
  42. # ftpStream.on 'data', (chunk) ->
  43. # console.log "Received #{chunk.length} bytes of data."
  44.  
  45. # ftpStream.on 'end', (detail) ->
  46. # console.log "detail:\n#{JSON.stringify(detail)}"
  47. # console.log "reading ended."
  48. # resolve(detail)
  49.  
  50. ftpStream.pipe(fs.createWriteStream(target))
  51.  
  52.  
  53. # did the stuff................................................................
  54. .catch (err) ->
  55. console.log "Shit shit fire ze missilez..."
  56. throw new Error(err)
  57.  
  58. .then () ->
  59. console.log "Completed."
  60. ftp.logout()
  61. process.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement