2017-10-27 1 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를 사용하여 고정했습니다.

관련 문제