Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Upload is successful, but getting error on check. C#

The WinSCP .NET assembly does not prevent you from overwriting the files. It's the server.

Post a session log file from WinSCP GUI, showing, how you override the files there.
Guest

Re: Upload is successful, but getting error on check. C#

I am able to overwrite files on the remote server using the WinSCP UI program with the same login so it doesn't appear to be an issue with the server.

Rob
Guest

Re: Upload is successful, but getting error on check. C#

I may have figured out what is causing the error. It seems like it is when the file already exists on the remote server.

Here is the scenario for one specific file:
2/20: file uploaded successfully
2/27: file upload failed
2/28: file upload failed
3/1: file upload failed

I am not setting the overwrite mode. I see on this page https://winscp.net/eng/docs/library_transferoptions that overwriting is the default, which is what I want.

Any suggestions?

Rob
Guest

Re: Upload is successful, but getting error on check. C#

Here is the PutFile method:
private TransferOperationResult PutFile(string fileName, bool isImage, string imagePath, TransferOptions transferOptions, Session session)
{
   var localPath = fileName;
   var remotePath = _practiceSettings.remotePath;
 
   if (isImage)
   {
      localPath = $"{imagePath}{fileName}";
      remotePath = _practiceSettings.remoteImagePath;
   }
 
   return session.PutFiles(localPath, remotePath, false, transferOptions);
}
Guest

Re: Upload is successful, but getting error on check. C#

Here is the session log. It looks like I am getting an access denied. (I had to mask certain parts of the file for privacy)
> 2021-02-26 08:38:04.771 Script: put  -nopermissions -nopreservetime -transfer="binary" -- "C:\MaskedFilePath\56343932-52d7-ea11-8104-0050568c65a2.pdf" "/"
. 2021-02-26 08:38:04.772 Copying 1 files/directories to remote directory "/" - total size: 151,921
. 2021-02-26 08:38:04.772   PrTime: No; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask:
. 2021-02-26 08:38:04.772   TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
. 2021-02-26 08:38:04.772   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2021-02-26 08:38:04.773 File: 'C:\MaskedFilePath\56343932-52d7-ea11-8104-0050568c65a2.pdf' [2021-02-26T11:31:16.087Z] [151921]
. 2021-02-26 08:38:04.773 Copying "C:\MaskedFilePath\56343932-52d7-ea11-8104-0050568c65a2.pdf" to remote directory started.
. 2021-02-26 08:38:04.773 Binary transfer mode selected.
. 2021-02-26 08:38:04.773 Starting upload of C:\MaskedFilePath\56343932-52d7-ea11-8104-0050568c65a2.pdf
> 2021-02-26 08:38:04.773 TYPE I
< 2021-02-26 08:38:04.809 200 Type set to I.
> 2021-02-26 08:38:04.809 PASV
< 2021-02-26 08:38:04.844 227 Entering Passive Mode (18,189,48,115,20,165).
> 2021-02-26 08:38:04.844 STOR 56343932-52d7-ea11-8104-0050568c65a2.pdf
. 2021-02-26 08:38:04.845 Connecting to 18.189.48.115:5285 ...
< 2021-02-26 08:38:04.881 550 Access is denied.
. 2021-02-26 08:38:04.881 Copying files to remote side failed.
* 2021-02-26 08:38:04.881 (ExtException) **Copying files to remote side failed.**
* 2021-02-26 08:38:04.881 Access is denied.
. 2021-02-26 08:38:04.881 Asking user:
. 2021-02-26 08:38:04.881 Error transferring file 'C:\MaskedFilePath\56343932-52d7-ea11-8104-0050568c65a2.pdf'. ("Copying files to remote side failed.","Access is denied. ")
< 2021-02-26 08:38:04.881 Script: Error transferring file 'C:\MaskedFilePath\56343932-52d7-ea11-8104-0050568c65a2.pdf'.
< 2021-02-26 08:38:04.882 Script: Copying files to remote side failed.
 
< 2021-02-26 08:38:04.882 Access is denied.
* 2021-02-26 08:38:04.882 (ESkipFile) Error transferring file 'C:\MaskedFilePath\56343932-52d7-ea11-8104-0050568c65a2.pdf'.
* 2021-02-26 08:38:04.882 Copying files to remote side failed.
* 2021-02-26 08:38:04.882 Access is denied.
. 2021-02-26 08:38:04.882 Copying finished: Transferred: 0, Elapsed: 0:00:00, CPS: 0/s
. 2021-02-26 08:38:04.882 Script: Failed

Here is my code
try
{
   //LogHelper.LogTrace(string.Format("Sending file '{0}' to client server.", fi.FileName));
   TransferOperationResult transferResult;
 
   var isImage = !fi.FileName.EndsWith(".xml");
 
   transferResult = PutFile(fi.FileName, isImage, imagesScrPath, transferOptions, session);
 
   //retry once if failure
   if (!transferResult.IsSuccess)
   {
      LogHelper.LogTrace($"First upload attempt of file '{fi.FileName}' failed for practice {_practiceSettings.practiceName}. Re-trying upload.");
      transferResult = PutFile(fi.FileName, isImage, _practiceSettings.remoteImagePath, transferOptions, session);
   }
 
   //check FTP result. if this fails, it goes into the catch below to log for upload error and increment the failed counter
   //transferResult.Check();
 
   if (!transferResult.IsSuccess)
   {
      LogHelper.LogError($"Second upload attempt of file '{fi.FileName}' failed for practice {_practiceSettings.practiceName}. Marking as failed.");
      failCount += 1;
      continue;
   }
 
   LogHelper.LogTrace($"Successfully uploaded file '{fi.FileName}' to client server for practice {_practiceSettings.practiceName}.");
   successCount += 1;
}
catch (Exception ex)
{
   var logMsg =
      string.Format("\r\n{0}\t{1}\tError uploading {4} file '{2}' in ftpFile. Continuing: {3}",
         DateTime.Now.ToShortDateString(),
         DateTime.Now.ToLongTimeString(),
         fi.FileName,
         ex.Message,
         this._practiceSettings.practiceName);
   LogHelper.LogError(logMsg, ex);
   failCount += 1;
}


I can go on the remote FTP server and see that 56343932-52d7-ea11-8104-0050568c65a2.pdf file.

Rob
martin

Re: Upload is successful, but getting error on check. C#

Please post your code and a session log file (Session.SessionLogPath).
rdlsz24

Upload is successful, but getting error on check. C#

Hi all, I use the WinSCP C# code to upload files to several FTP/SFTP servers each day. I am only having an issue with one server right now, where I get errors that files failed to upload, but when I look on the remote server I see them. It is not all file checks that throw the errors; the majority work fine. It is not the usual permissions issue that is documented on here, as we have had the transferOptions.FilePermissions = null and transferOptions.PreserveTimestamp = false in place for several years now.

If I call the transferResult.Check() for each upload, it will go into the Catch, and I get:

System Error. Code: 2.
The system cannot find the file specified | File or folder 'SomeFile.txt' does not exist.
System Error. Code: 2.
The system cannot find the file specified SessionRemoteException

I tried switching to !transferResult.IsSuccess, but I get the same issue, where it thinks the file failed to upload when it didn't.

I will mention that the remote FTP server was recently changed, either to a new server, or just had the address updated. Would there be any sort of setting on the new server that I could inform them about to alleviate these errors? I really hate to turn off upload validation, but it is causing concern on daily reports when there really is no issue.

Thanks,
Rob