首页 \ 问答 \ ChannelSftp:创建新文件或临时文件(ChannelSftp: create new or temporary file)

ChannelSftp:创建新文件或临时文件(ChannelSftp: create new or temporary file)

我目前正在使用JSch使用SFTP访问某些文件,我还需要在远程服务器上对每个文件执行一些更改。

我可以使用ChannelSftp访问和读取文件,但我想在此远程目录中创建一个临时文件。 我看不到这样做的方法。 我有能力制作目录和删除文件,但不能创建一个空文件? 这是你可以使用ChannelSftp做的事吗?


I am currently using JSch to access some files using SFTP and I also need to perform some changes in each file once it is on the remote server.

I am able to access and read the files using ChannelSftp but I would like to create a temporary file while in this remote directory as well. I cannot see a way to do this. I have the ability to make directories and remove files, but not create an empty file? Is this something you can do using ChannelSftp?


原文:https://stackoverflow.com/questions/35729047
更新时间:2022-09-13 09:09

最满意答案

奇怪的是,答案很直截了当。 这是我如何做到的:

let array = Array(results) // la fin

I found a solution. Created extension on Results.

extension Results {
    func toArray<T>(ofType: T.Type) -> [T] {
        var array = [T]()
        for i in 0 ..< count {
            if let result = self[i] as? T {
                array.append(result)
            }
        }

        return array
    }
}

and using like

class func getSomeObject() -> [SomeObject]? {
    let objects = Realm().objects(SomeObject).toArray(SomeObject) as [SomeObject]

    return objects.count > 0 ? objects : nil
}

相关问答

更多