Using the N/sftp module. I am trying to move the f...
# suitescript
n
Using the N/sftp module. I am trying to move the file from one folder to another. Here is my object that I am passing to the script {"from":"/NetSuiteUpload/20240908_AP_d5b9c99a.csv","to":"/Archived/20240908_AP_d5b9c99a.csv"} And here is the error I get from NetSuite: _Source 'NetSuiteUpload/20240908_AP_d5b9c99a*.csv/*' must be readable and destination 'Archived/20240908_AP_d5b9c99a.*csv/*' must be writable._ I have checked that the file exist and that I can move the file manually via WinSCP. I believe the problem is that NetSuite is appending the additional "/" after the .csv. Any thoughts or suggestions?
m
Yeah, looks like it’s treating your files as directories with the ending “/“ there. What does the actual SFTP code look like?
n
Copy code
let obj = {
    from: sftpFolder + fileName,
    to: archiveFolder + fileName
};

log.audit('Move obj', obj);

sftpConnection.move(obj);
m
Two thoughts Try hardcoding the from and to strings to see if that works. Maybe the variable is picking up something wierd. Try the locations with out the beginning "/", do "_NetSuiteUpload/20240908_AP_d5b9c99a*.csv" instead of "/*NetSuiteUpload/20240908_AP_d5b9c99a*.csv". The sample code in the help shows the paths without a starting "/"*_
n
I hardcoded the path like you suggested. Still got the same error with the "/" at the end.
I hardcoded with "/" and without "/" at the beginning.
m
Then it must just be a generic way the error message is reported from suitescript. Have you checked on the read and write permissions on the machine hosting the two directories?
n
I can manually move file using the same SFTP user.
Read and write permissions are also there.
m
Oh, did you set a directory value on when doing sftp.createConnection?
n
I set the root directory "/"
m
try without setting that value possibly?
n
Ok, let me check.
Still the same.
m
I'm at a loss at this point. There must be something different with how the destination machine is seeing the user from NetSuite compared to when you use WinSCP, having a permissions issue.
n
Thanks for your input. I am reaching out to NetSuite Support as well.
a
yeah those params are for directories, not specific files.
n
But description says "moves a file or directory"
a
well it will move the contents of a directory... if those contents are FILEs or DIRECTORIES it will move them
n
Params description says "The relative path of the file to be moved from"
a
and the code?
m
The descriptions for the params are a bit miss leading, as there's no param to indicate the file name of the file to be moved. The sample code for the move function shows the pats with a file name in it also
a
what's your use case for moving a file to different folder?
n
I process a file. Then move it to Archived folder.
m
Copy code
// Move the test file to the new directory
    log.debug('Moving the test file from "test" to "test2"...');
    connection.move({
        from: 'yyy/test/af.txt',
        to: 'yyy/test2/af.txt'
    })
    log.debug('File moved!');
a
yeah so don't use move download finish process successfully upload to archived remove file from unarchived
n
Thanks for this alternative @Anthony OConnor I will need to use it since it is impacting the client's business.
Did it work @Matt Carter?
m
Sorry, I haven't tried it, that's from the samples in the SuiteScript documentation
a
huh, yeah i didn't see that, I guess maybe it is supposed to support files too, in that case still submit the support ticket
n
It does move file @Anthony OConnor I have used it before. This specific client is facing issue.
m
I might give it a shot if I still have an SFTP setup somewhere to use at the moment
a
at the very list they should fix the docs, but idk why it wouldn't support file moving
oh? huh okay then that's very weird
n
But those had files at the root level. This one has sub-folders.
a
Here is my object that I am passing to the script
Copy code
{
  "from": "/NetSuiteUpload/20240908_AP_d5b9c99a.csv",
  "to": "/Archived/20240908_AP_d5b9c99a.csv"
}
is there a reason your from and to are wrapped in quotes?
n
They are not in my code. I copied the full path from the logs, so that's why they are in quotes.
👍 1
m
Are you using the same auth on with the suitscript and when using WinSCP, I mean using pass and user or user and ssh key in both ways on connecting?
n
Yes
m
Weird
n
I created the "Archived" folder in the NetSuiteUpload folder and the file moved successfully.
a
i was almost going to suggest that but figured I'd sound like a crazy person
n
At least now I know it's related to the path and the code itself.
m
Ok, guess the destination machine has issues resolving relative paths properly then. It’s seeing the NetSuiteUpload as the base after grabbing the file from there. It probably won’t work, but maybe try a move back directory indicator in the path “../Arvhived/file.csv”
n
I tried that... didn't work.
Customer is fine with the "Archived" folder. The end goal is that the files are not processed twice.
Thanks @Matt Carter and @Anthony OConnor
👍 1
m
Welcome!