2017-10-27 11 views
0

sftpアップロードにDLFTPClientを使用しています。これは私のコードです。Swiftでアップロードしようとするとローカルファイルが読み込めない

var connection: DLSFTPConnection = DLSFTPConnection(hostname: "192.168.1.1", port: 2222, username: "test", password: "test") 
var remoteBasePath = "/test" 
var localPath: String = Bundle.main.url(forResource: "test", withExtension: ".jpg")?.absoluteString 
var request: DLSFTPRequest? 


override func viewDidLoad() { 
    super.viewDidLoad() 

    var successBlock = {() -> Void in 
     DispatchQueue.main.async(execute: {() -> Void in 
      // login successful 
      print("loginSuccess") 
     }) 
     } as? DLSFTPClientSuccessBlock 

    var failureBlock = {(_ error: Error?) -> Void in 
     DispatchQueue.main.async(execute: {() -> Void in 

      print(error) 
     }) 
     print("error") 
     } as? DLSFTPClientFailureBlock 
    connection.connect(successBlock: successBlock, failureBlock: failureBlock) 
} 


@IBAction func startTapped(_ sender: Any) { 
    print("sending") 

    var successBlock = {(_ file: DLSFTPFile, _ startTime: Date, _ finishTime: Date) -> Void in 
     DispatchQueue.main.async(execute: {() -> Void in 

      var alertView = UIAlertView(title: "Upload completed", message: "", delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "") 
      alertView.show() 
     }) 
     print("success") 
     } as? DLSFTPClientFileTransferSuccessBlock 

    var failureBlock = {(_ error: Error?) -> Void in 
     DispatchQueue.main.async(execute: {() -> Void in 

      print(error) 
     }) 
     print("error") 
     } as? DLSFTPClientFailureBlock 

    var localFilename = "test.jpg" 
    var remotePath: String = URL(fileURLWithPath: remoteBasePath).appendingPathComponent(localFilename).absoluteString 
    request = DLSFTPUploadRequest(remotePath: remotePath, localPath: localPath, successBlock: successBlock, failureBlock: failureBlock, progressBlock: nil) 
    connection.submitRequest(request) 

} 

ログインしようとするとすべてうまくいっているようですが、成功します。しかし、ファイルをアップロードしようとするとエラーが返されます:(エラードメイン= SFTPClientErrorDomainコード= 29「ローカルファイルが読み込めない」UserInfo = {NSLocalizedDescription =ローカルファイルが読み込めません})

私のリモートに問題がありますかベースパスとローカルパス?事前にありがとうございます。

+0

'remotePath'は' file:// '体系のURL文字列です。私はこれが意図されているのか疑問です。 – vadian

答えて

0

localPathとremotePathで.absoluteStringの代わりに.pathを使用して修正しました。

関連する問題