Advertisement
Guest User

Untitled

a guest
May 13th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. import Foundation
  2. import NMSSH
  3.  
  4. /**
  5. SFTP Data Transfer Provider is a way of getting SFTP Data
  6. */
  7. public class SFTPFileDataProvider {
  8.  
  9. private var privateKeyPath: String?
  10. private var publicKeyPath: String?
  11. private let keyPassword = ""
  12. private let userName: String
  13. private let host: String
  14. private let port: Int
  15.  
  16. /**
  17. Initializes a new SFTP Connection with host and (optional) port
  18.  
  19. - parameter host: hostname of SFTP server
  20. - parameter port: _OPTIONAL_ defaults to 22
  21. */
  22. init(host: String, port: Int = 22, userName: String) {
  23. self.userName = userName
  24. self.host = host
  25. self.port = port
  26. }
  27.  
  28.  
  29. /**
  30. Returns a NMSFTP session with the configured data elements
  31.  
  32. - returns: a session that is hopefully connected
  33. */
  34. func ftpSession() -> NMSFTP {
  35. let c = NMSSHSession.connectToHost(self.host, port: self.port, withUsername: self.userName)
  36. c.authenticateByPassword("password")
  37. return NMSFTP.connectWithSession(c)
  38. }
  39.  
  40. public static func test() {
  41. testFTP()
  42. }
  43. }
  44.  
  45.  
  46. class TMonkey {
  47. func test() {
  48. testFTP()
  49. }
  50. }
  51.  
  52.  
  53. func testFTP() {
  54.  
  55. let sftp: NMSFTP = SFTPFileDataProvider(host: "test.rebex.net:22", userName: "demo").ftpSession()
  56.  
  57. for f in sftp.contentsOfDirectoryAtPath("/") {
  58. print (f)
  59. }
  60. }
  61.  
  62. func test2Good() {
  63. let t = TMonkey()
  64. t.test()
  65. testFTP()
  66. }
  67.  
  68. // UNCOMMENT TO HAVE A BUILD FAILURE
  69. func testCompileIssue() {
  70. let sftp = SFTPFileDataProvider(host: "test.rebex.net:22", userName: "demo")
  71. }
  72.  
  73. // UNCOMMENT TO HAVE A BUILD FAILURE
  74. func testStatic() {
  75. SFTPFileDataProvider.test()
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement