FTP.Rename doesn't work in SFTP

Hi all,

I have a FTP.Inbounding service that read a file and move it to a other folder when it is processed. The problem is that is not working fine in SFTP server.

The code is coppied from How to - Customize Ensemble Settings article.

// begin customization code
// get the Filename, attach the time stamp to it and move the file into the Archive directory
// the Rename method below is using RNFR and RNTO FTP commands (RFC 959), effectively moving the file into the new directory
Set tSource=pInput.Attributes("Filename")
Set tArchive=..Adapter.CreateTimestamp(tSource,"%f_%Q")
set fullPath =..RemoteArchivePath_"\"_tArchive 
$$$TRACE("Path for archive: "_fullPath)
        
Set tSC=..Adapter.rename(tSource,fullPath,..Adapter.%serverPath)


It works if I'm using a simple FTP server, however if I use SFTP it doesn't work.

I'm been investigating (and debuging) the code and It uses the method EnsLib.FTP.CommonSSH.RenameSSH

Method RenameSSH(OldFilename As %String, NewFilePath As %String) As %Boolean [ Internal ]
{
   Set tNew=$S(NewFilePath["/":NewFilePath, 1:..%serverPath_NewFilePath)
   Set tSC=..%sftpSession.Rename(..%serverPath_OldFilename, tNew), ..ReturnCode=0, ..ReturnMessage=""
   If $$$ISERR(tSC) Set ..ReturnMessage="Error in SFTP Rename("_..%serverPath_OldFilename_","_tNew_") "_$$$StatusDisplayString(tSC) Quit 0
   Quit 1
}

the %sftpSession.Rename thow an error:

SFTP Error [80102003]: Permission Denied [80102003] at SFTP.cpp:439,0

My first attempt was to check the connection credentials to the SFTP, so using an FTP manager I connected with the same credentials and the renaming and moving the file has been done correctly, I do not understand the "permission denied" error message, thenfore it should be other thing.

Any one can throw light to this problem?

Best regards,

Francisco Lopez 

  • 0
  • 0
  • 76
  • 4
  • 0

Comments

Hi Francisco,

At a guess, I would say your FTP user account doesn't have permission to write into the archive path.

Yes, the account has permission to write and delete. Also to create and remove folders.

I just re-read and see you have tried from a different client, maybe Ensemble is losing the connection, I will have a look around the code.

A couple of thoughts, as you have a backslash in the path, the new file path is going to be a concat of ..Adapter.%serverPath and NewFilePath, I would log this and not just the fullPath so you can be sure what directory you are trying to write to...

$$$TRACE("Path for archive: "_..Adapter.%serverPath_NewFilePath)

Also, might just be worth checking that you are connected when you do the rename

$$$TRACE("Connected: ",..Adapter.Connected)