```type":"error.SuiteScriptError","name":"UNEXPECT...
# suitescript
j
Copy code
type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["anonymous(N/file)","onRequest(/SuiteScripts/NFG BJ SL Test Upload.js:48)"],"cause":{"type":"internal error","code":"UNEXPECTED_ERROR","details":null,"userEvent":null,"stackTrace":["anonymous(N/file)","onRequest(/SuiteScripts/NFG BJ SL Test Upload.js:48)"],"notifyOff":false},"id":"da8c4901-f893-42f8-8658-6b73bb0bd000-2d323032302e30332e3230","notifyOff":false,"userFacing":false}
Anyone know what might be going on here? It's an SFTP connection, I was able to establish and look through the directories as well as download from it. Doing an upload and I'm getting the above. Simple code... but maybe I'm missing something. First time working with the SFTP module.
Copy code
var myFile = file.load({
    id: 21185724
});
connection.upload({
    file: myFile,
    directory: ''
});
s
Are you repeatedly unable to upload with the same error? Have you retried several times?
s
I am goign to assume the connection established properly?
Copy code
try {
            connection = sftp.createConnection({
                username: 'xxx',
                passwordGuid: myPwdGuid,
                url: '<http://xxx.com|xxx.com>',
                directory: '/relative/filepath',
                hostKey: myHostkey
            });
        } catch (e) {
            log.error({
                title: 'connection error',
                details: e.message
            });
            context.write({
                key: 'connection',
                value: e.message
            });
        }
        //loops through values array and builds master string
        var results = context.values;
        var final = "";
        for (var i = 0; i < results.length; i++) {
            final = final + results[i];
        }
        //used for naming the file
        var date = new Date();
        var tdate = date.getDate();
        var month = date.getMonth() + 1; // jan = 0
        var year = date.getFullYear();
        var currentDate = month + '.' + tdate + '.' + year;
        var fileName = 'file upload ' + currentDate;
        //file creation to post to SFTP and save in file cabinet
        var fileobj = file.create({
            name: fileName,
            fileType: file.Type.PLAINTEXT,
            contents: final,
            folder: someid,
            isOnline: true
        });
        var id = fileobj.save();
        try {
            //attempt to upload to SFTP
            connection.upload({
                directory: '/',
                filename: fileName,
                file: fileobj,
                replaceExisting: true
            });
        } catch (e) {
            log.error({
                title: 'upload failed',
                details: e.message
            });
            context.write({
                key: 'upload',
                value: e.message
            });
        }
I used to use this successfully, hopefully yours is somethign similar (this was in reduce stage of an MR)
b
make sure you have permission to upload to that directory
j
Thanks, @Sandii, and @battk. The sample will be nice to work off of. I'll contact the host of the server to make sure I have upload permission. I'm thinking that the most probable cause. @SimonC, yeah I tried a few times in a few different ways changing little things like the directory being "" vs "/" etc.
b
it should be fairly easy to confirm if you use actual sftp software like filezilla
j
Good idea.
@battk, I uploaded through filezilla and it said transfer was successful, but the xml I uploaded doesn't appear in the root directory where it said I put it. Maybe I need to contact the provider... I'm at a loss.
b
its fairly common for integrations that use sftp to automatically move files
j
Yeah, that was the case. It just picked up the file fast so I didn't see it.
So FileZilla works, but my test suitelet isn't uploading.
b
or any other sftp server you have access to
demo.wftpserver.com has a upload directory you can try
j
Yeah. Also I'm thinking I should try a simpler file. Like a basic .txt to make sure the xml file I built isn't the problem.
Figured it out. The company I'm working with automatically moves me to a subfolder when I was in FileZilla. I had to add an extra path in my script to get to the correct account-root directory. Interesting that this comes back as unknown error. I'd feel like I should/could have gotten a permission error or something instead.
b
permission errors throw as unexpected errors
not very useful