gpt4 book ai didi

swift - 尝试在 Swift 中上传时本地文件不可读

转载 作者:可可西里 更新时间:2023-11-01 01:11:10 27 4
gpt4 key购买 nike

我正在使用 DLFTPClient 进行 sftp 上传。这是我的代码。

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)

}

当我尝试登录时似乎一切正常,它返回成功。但是,当我尝试上传文件时,它返回错误:(Error Domain=SFTPClientErrorDomain Code=29 "Local file is not readable"UserInfo={NSLocalizedDescription=Local file is not readable})

我的远程基本路径和本地路径有问题吗?非常感谢您。

最佳答案

我在 localPath 和 remotePath 中使用 .path 而不是 .absoluteString 修复了它。

关于swift - 尝试在 Swift 中上传时本地文件不可读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46968011/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com