SFTPWrapper.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // This wrapper class is used to retain backwards compatibility with
  2. // pre-v0.4 ssh2. If it weren't for `read()` and `write()` being used by the
  3. // streams2/3 API, we could just pass the SFTPStream directly to the end user...
  4. var inherits = require('util').inherits;
  5. var EventEmitter = require('events').EventEmitter;
  6. function SFTPWrapper(stream) {
  7. var self = this;
  8. EventEmitter.call(this);
  9. this._stream = stream;
  10. stream.on('error', function(err) {
  11. self.emit('error', err);
  12. }).on('end', function() {
  13. self.emit('end');
  14. }).on('close', function() {
  15. self.emit('close');
  16. }).on('continue', function() {
  17. self.emit('continue');
  18. });
  19. }
  20. inherits(SFTPWrapper, EventEmitter);
  21. // stream-related methods to pass on
  22. SFTPWrapper.prototype.end = function() {
  23. return this._stream.end();
  24. };
  25. // SFTPStream client methods
  26. SFTPWrapper.prototype.createReadStream = function(path, options) {
  27. return this._stream.createReadStream(path, options);
  28. };
  29. SFTPWrapper.prototype.createWriteStream = function(path, options) {
  30. return this._stream.createWriteStream(path, options);
  31. };
  32. SFTPWrapper.prototype.open = function(path, flags, attrs, cb) {
  33. return this._stream.open(path, flags, attrs, cb);
  34. };
  35. SFTPWrapper.prototype.close = function(handle, cb) {
  36. return this._stream.close(handle, cb);
  37. };
  38. SFTPWrapper.prototype.read = function(handle, buf, off, len, position, cb) {
  39. return this._stream.readData(handle, buf, off, len, position, cb);
  40. };
  41. SFTPWrapper.prototype.write = function(handle, buf, off, len, position, cb) {
  42. return this._stream.writeData(handle, buf, off, len, position, cb);
  43. };
  44. SFTPWrapper.prototype.fastGet = function(remotePath, localPath, opts, cb) {
  45. return this._stream.fastGet(remotePath, localPath, opts, cb);
  46. };
  47. SFTPWrapper.prototype.fastPut = function(localPath, remotePath, opts, cb) {
  48. return this._stream.fastPut(localPath, remotePath, opts, cb);
  49. };
  50. SFTPWrapper.prototype.readFile = function(path, options, callback_) {
  51. return this._stream.readFile(path, options, callback_);
  52. };
  53. SFTPWrapper.prototype.writeFile = function(path, data, options, callback_) {
  54. return this._stream.writeFile(path, data, options, callback_);
  55. };
  56. SFTPWrapper.prototype.appendFile = function(path, data, options, callback_) {
  57. return this._stream.appendFile(path, data, options, callback_);
  58. };
  59. SFTPWrapper.prototype.exists = function(path, cb) {
  60. return this._stream.exists(path, cb);
  61. };
  62. SFTPWrapper.prototype.unlink = function(filename, cb) {
  63. return this._stream.unlink(filename, cb);
  64. };
  65. SFTPWrapper.prototype.rename = function(oldPath, newPath, cb) {
  66. return this._stream.rename(oldPath, newPath, cb);
  67. };
  68. SFTPWrapper.prototype.mkdir = function(path, attrs, cb) {
  69. return this._stream.mkdir(path, attrs, cb);
  70. };
  71. SFTPWrapper.prototype.rmdir = function(path, cb) {
  72. return this._stream.rmdir(path, cb);
  73. };
  74. SFTPWrapper.prototype.readdir = function(where, opts, cb) {
  75. return this._stream.readdir(where, opts, cb);
  76. };
  77. SFTPWrapper.prototype.fstat = function(handle, cb) {
  78. return this._stream.fstat(handle, cb);
  79. };
  80. SFTPWrapper.prototype.stat = function(path, cb) {
  81. return this._stream.stat(path, cb);
  82. };
  83. SFTPWrapper.prototype.lstat = function(path, cb) {
  84. return this._stream.lstat(path, cb);
  85. };
  86. SFTPWrapper.prototype.opendir = function(path, cb) {
  87. return this._stream.opendir(path, cb);
  88. };
  89. SFTPWrapper.prototype.setstat = function(path, attrs, cb) {
  90. return this._stream.setstat(path, attrs, cb);
  91. };
  92. SFTPWrapper.prototype.fsetstat = function(handle, attrs, cb) {
  93. return this._stream.fsetstat(handle, attrs, cb);
  94. };
  95. SFTPWrapper.prototype.futimes = function(handle, atime, mtime, cb) {
  96. return this._stream.futimes(handle, atime, mtime, cb);
  97. };
  98. SFTPWrapper.prototype.utimes = function(path, atime, mtime, cb) {
  99. return this._stream.utimes(path, atime, mtime, cb);
  100. };
  101. SFTPWrapper.prototype.fchown = function(handle, uid, gid, cb) {
  102. return this._stream.fchown(handle, uid, gid, cb);
  103. };
  104. SFTPWrapper.prototype.chown = function(path, uid, gid, cb) {
  105. return this._stream.chown(path, uid, gid, cb);
  106. };
  107. SFTPWrapper.prototype.fchmod = function(handle, mode, cb) {
  108. return this._stream.fchmod(handle, mode, cb);
  109. };
  110. SFTPWrapper.prototype.chmod = function(path, mode, cb) {
  111. return this._stream.chmod(path, mode, cb);
  112. };
  113. SFTPWrapper.prototype.readlink = function(path, cb) {
  114. return this._stream.readlink(path, cb);
  115. };
  116. SFTPWrapper.prototype.symlink = function(targetPath, linkPath, cb) {
  117. return this._stream.symlink(targetPath, linkPath, cb);
  118. };
  119. SFTPWrapper.prototype.realpath = function(path, cb) {
  120. return this._stream.realpath(path, cb);
  121. };
  122. // extended requests
  123. SFTPWrapper.prototype.ext_openssh_rename = function(oldPath, newPath, cb) {
  124. return this._stream.ext_openssh_rename(oldPath, newPath, cb);
  125. };
  126. SFTPWrapper.prototype.ext_openssh_statvfs = function(path, cb) {
  127. return this._stream.ext_openssh_statvfs(path, cb);
  128. };
  129. SFTPWrapper.prototype.ext_openssh_fstatvfs = function(handle, cb) {
  130. return this._stream.ext_openssh_fstatvfs(handle, cb);
  131. };
  132. SFTPWrapper.prototype.ext_openssh_hardlink = function(oldPath, newPath, cb) {
  133. return this._stream.ext_openssh_hardlink(oldPath, newPath, cb);
  134. };
  135. SFTPWrapper.prototype.ext_openssh_fsync = function(handle, cb) {
  136. return this._stream.ext_openssh_fsync(handle, cb);
  137. };
  138. module.exports = SFTPWrapper;