<commit_before>var Connection = require('ssh2');

var sftp = function() {
    var c = new Connection();
    var sftp_key = "/home/admin/.ssh/sftp_key";
    var ip;

    var connect = function(ipAddress) {
        ip = ipAddress;
    };

    var upload = function(tempFilename, filename, next) {
        c.on('ready', function() {
            console.log('Connection :: ready');

            c.sftp(function(err, sftp) {
                if (err) throw err;

                sftp.fastPut(tempFilename, filename, function(err) {
                    if (err) {
                        console.log("upload of file failed. " + ip);
                        next(err);
                    } else {
                        console.log("upload of file succeeded: " + ip);
                        next();
                    }
                });

                sftp.on('end', function() {
                    console.log('SFTP :: SFTP session closed');
                });

                sftp.close();
            });
        });

        c.on('error', function(err) {
            console.log('Connection :: error :: ' + err);
        });

        c.on('end', function() {
            console.log('Connection :: end');
        });

        c.on('close', function() {
            console.log('Connection :: close');
        });

        c.connect({
            host: ip,
            port: 22,
            username: 'singular_user',
            privateKey: require('fs').readFileSync(sftp_key)
        });
    };

    return {
        connect: connect,
        upload: upload
    }
};
<commit_msg>error message for file upload with sftp<commit_after>var Connection = require('ssh2');

var sftp = function() {
    var c = new Connection();
    var sftp_key = "/home/admin/.ssh/sftp_key";
    var ip;

    var connect = function(ipAddress) {
        ip = ipAddress;
    };

    var upload = function(tempFilename, filename, next) {
        c.on('ready', function() {
            console.log('Connection :: ready');

            c.sftp(function(err, sftp) {
                if (err) throw err;

                sftp.fastPut(tempFilename, filename, function(err) {
                    if (err) {
                        console.log("upload of file failed. " + ip);
                        next(err);
                    } else {
                        console.log("upload of file succeeded: " + ip);
                        next();
                    }
                });

                sftp.on('end', function() {
                    console.log('SFTP :: SFTP session closed');
                });
            });
        });

        c.on('error', function(err) {
            console.log('Connection :: error :: ' + err);
        });

        c.on('end', function() {
            console.log('Connection :: end');
        });

        c.on('close', function() {
            console.log('Connection :: close');
        });

        c.connect({
            host: ip,
            port: 22,
            username: 'singular_user',
            privateKey: require('fs').readFileSync(sftp_key)
        });
    };

    return {
        connect: connect,
        upload: upload
    }
};

{'fraction_non_alphanumeric': 0.13993066498581783, 'fraction_numerical': 0.0018909549322407816, 'mean_word_length': 1.2867435158501441, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '385211', 'n_tokens_mistral': 891, 'n_tokens_neox': 818, 'n_words': 179}