ios – NMSSH truncates uploaded file


I upload a file to a server using NMSSH.

let localURL = ...
let sshSession = NMSSHSession.connect(toHost: "MYHOST", withUsername: "MYUSERNAME")
if sshSession.isConnected {
    sshSession.authenticate(byPassword: "MYPASSWORD")
    if sshSession.isAuthorized {
        let sftpSession = NMSFTP(session: sshSession)
        sftpSession.connect()
        if sftpSession.isConnected {
            let data = try? Data(contentsOf: localURL)
            sftpSession.writeContents(data, toFileAtPath: "./uploads/MYFILE")
            sftpSession.disconnect()
        } else {
            // sftpSession is not connected
        }
    } else {
        // sshSession is not authorized
    }
    sshSession.disconnect()
} else {
    // sshSession is not connected
}

After the app is productive several months now, I noticed that about 1% of all uploaded files are truncated by multiple of 16384 bytes (e.g. 16384, 32768, …). The behaviour is not reproducable. I can upload the same sample test file (of e.g. 30000 bytes) many times and it works fine, but sometimes the server file only holds the first 16384 bytes.

I believe (!?) some buffered data is not entirely flushed prior sftpSession is disconnected, but that’s just a wild guess. Besides that, I would have no clue how to fix that.

Any ideas why data is truncated?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img