0 votes
by (140 points)

Hi

I'm trying to upload files to a server that connects with a Private Key. We need to preserve the date of the files, so we have client.Settings.RestoreDateTime = ItemDateTimes.LastWriteTime, and the TransferMethod on the upload is set to TransferMethod.Move. We get the below error when we upload:

2023-09-25 21:31:16.241 +08:00 [WRN] FtpSiteActions.Connect: Getting Private key with passphrase
2023-09-25 21:31:16.830 +08:00 [INF] ***Executing Definition - Starting upload for definition 26***
2023-09-25 21:31:17.412 +08:00 [WRN] UPLOAD failed for C:\Datafiles\Uploads
2023-09-25 21:31:17.427 +08:00 [ERR] Cannot upload file ('C:\Datafiles\Uploads\5020_Uploads_TEST.csv'). Unsupported operation; SETSTAT unsupported.
Rebex.Net.SftpException: Cannot upload file ('C:\Datafiles\Uploads\5020_Uploads_TEST.csv'). Unsupported operation; SETSTAT unsupported.
---> Rebex.Net.SftpException: Unsupported operation; SETSTAT unsupported.
   at kpta.drdr(omwn arv, Type arw)
   at kpta.drdd(String aqg, SftpAttributes aqh, kpsk aqi)
   at Rebex.Net.Sftp.qbes(String uk, SftpAttributes ul, kpsk um)
   at Rebex.Net.Sftp.qbdr(kpub qm, kpsk qn, String qo, String qp, Int64 qq, Int64 qr, Int64 qs, omxj qt)
   at kpsv.rfig(kpub anj, String ank, String anl, Int64 anm, Int64 ann)
   --- End of inner exception stack trace ---
   at omxg.egzt(Exception ewq, TransferProblemType ewr, omxd ews, omxd ewt, BatchProblemReactions ewu, BatchProblemReactions ewv, BatchProblemReactions& eww)
   at omxg.egzs(Exception ewj, String ewk, TransferProblemType ewl, omxd ewm, omxd ewn, BatchProblemReactions ewo, BatchProblemReactions& ewp)
   at omxg.egzl(String evk, String evl, omxd evm, omxd evn, omxd evo, omxd evp, Boolean evq, Boolean evr, Boolean evs)
   at omxg.egzk(omxe evj)
   at omxg.egzh()
   at omxg.egzc(TransferAction euu, omxc euv, String euw, TransferMethod eux, MoveMode euy, LinkProcessingMode euz, ActionOnExistingFiles eva, omxd evb)
   at Rebex.Net.Sftp.qbev(TransferAction ut, kpsk uu, kpsu uv, String uw, TransferMethod ux, MoveMode uy, LinkProcessingMode uz, ActionOnExistingFiles va)
   at Rebex.Net.Sftp.qbfn(Object wv, Enum ww, Object[] wx)
   at omjz.gsbm(Object iz)
--- End of stack trace from previous location ---

If I upload the same files to our sftp sever we don't get the SETSTAT unsupported error, so it appears to be a setting on the server. It also appears that the file is uploaded, but it's not deleted when the upload has completed?

Applies to: Rebex SFTP

1 Answer

0 votes
by (148k points)

Apparently, the server does not support SFTP protocol's SETSTAT operation that is used by the SFTP client to update the file's last write time attribute. This is most likely either a deliberate choice of the server maintainers, or a limitation of the underlying file system of the server's file storage. To find out the exact reason, you would have to ask the server operators.

When an error like this occurs, Rebex SFTP client does not delete the remote file. It also does even delete the file when any other error occurs during the transfer, even if it has not been fully uploaded. We believe the choice whether to delete the file or not is best left to the client application.

by (140 points)
Thank you Lukas - is there a way we can gracefully trap the SETSTAT error so that the upload will still proceed, and then handle the file deletion separately if needs be. I am aware of the ProblemDetected event - would the SETSTAT operation failure raise a TransferProblemType.UnsupportedFeature event at all?
by (73.6k points)
Unfortunately, SETSTAT operation failure would result into CannotTransferFile instead of UnsupportedFeature. At the moment, the date restoration is part of the upload process.

However, if we handle date restoration differently, the process would still detect an error so it will not delete source files after successful transfer (the Move operation changes to Copy operation in case of any error).

Given that, it seems that the best approach is to turn off date restoration and prevent any errors of such kind. You can do it either hard-coded for this particular server, of if you need to detect it automatically, just simply try to update time on a well known file or directory, like this:

  client.SetFileDateTime(".", DateTime.Now);

if the SetFileDateTime() fails with the expected error, turn off date restoration like this:

  client.Settings.RestoreDateTime = ItemDateTimes.None;
...