-2

I know how to copy a file in sftp server. But, how to put files in a sftp folder to a suitescript array? Also, is it possible to move or delete a file in sftp server using suite script 2.0? If yes, how to do it?

The following coding is for copying a file in sftp:

    var myPwdGuid = "B34672495064525E5D65032D63B52301";
    var myHostKey = "AAA1234567890Q=";

    var connection = sftp.createConnection({
        username: 'myuser',
        passwordGuid: myPwdGuid,
        url: 'host.somewhere.com',
        directory: 'myuser/wheres/my/file',
        hostKey: myHostKey
    });

    var downloadedFile = connection.download({
        directory: 'relative/path/to/file',
        filename: 'downloadMe.js'
    });

    connection.upload({
        directory: 'relative/path/to/remote/dir',
        filename: 'copy_of_downloadme.js',
        file: downloadedFile,
        replaceExisting: true
    });
chwh
  • 1
  • 2
  • I just find out that sftp module doesn't include a way to list the files/folders on the SFTP server. I get this information from this site: http://www.upilioconsulting.com/2016/10/05/netsuite-2016-2-sftp-suitescript-2-0/. So, how do people download the file that they want from sftp server? – chwh Nov 27 '17 at 01:05

1 Answers1

0

Indeed, the SFTP module in its current version does not include a way to list the contents of a remote directory. In some scenarios the file name is known or predictable. For the other scenarios one can use a file with a known name to store the names of the other files or middleware to retrieve the list of files. Ask me if you want to know about an existing middleware solution.

Maria Berinde-Tampanariu
  • 1,011
  • 1
  • 12
  • 25