Hari
Hari

Reputation: 19

WinSCP error while uploading file occurring randomly

We are using WinSCP to transfer files to a SFTP server by invoking commands in .net code. On the other end, an automated process grabs the file and moves it to another location. The below is the .Net code being used.

With winscp.StandardInput 
   .WriteLine("option batch abort") 
   .WriteLine("option confirm off") 
   .WriteLine("open sftp://" & username & ":" & password & "@" & remotehost) 
   .WriteLine("option transfer binary") 
   .WriteLine("lcd " & localFilePath) 
   If Not remoteFilePath Is Nothing Then .WriteLine("cd " & remoteFilePath) 
   If remoteFileName Is Nothing Then .WriteLine("put " & localFileName) Else .WriteLine("put " & localFileName & " """ & remoteFileName & """") 
   .Close() 
End With

In some cases, when the WinSCP issues the PUT command,

  1. Creates the partial file
  2. Renames it back to original name
  3. The process at the other end moves the file
  4. Then our process creates the partial file again and tries to delete the file with original name.

Not sure why the step#4 is happening, as we don't have any logic in our code to place the partial file again and delete the original file.

Please see the following log from the SFTP server.

  1. 2015-03-05 22:30:59 - Account\UserID [3346178]created /in/YYYXXX.xml.filepart - 226 - 1178853 - 22
  2. 2015-03-05 22:31:21 - Account\UserID [3346178]rnfr /in/YYYXXX.xml.filepart - 350 - - 22
  3. 2015-03-05 22:31:21 - Account\UserID [3346178]rnto /in/YYYXXX.xml - 250 - - - 22
  4. 2015-03-05 22:31:25 - Account\UserID [3346215]sent /in/YYYXXX.xml - 226 - 17924096 - 22
  5. 2015-03-05 22:31:26 - Account\UserID [3346220]dele /in/YYYXXX.xml - 250 - - - 22
  6. 2015-03-05 22:31:28 - Account\UserID [3346209]created /in/YYYXXX.xml.filepart - 226 - 1178853 - 22
  7. 2015-03-05 22:31:28 - Account\UserID [3346209]dele /in/YYYXXX.xml - 550 - - - 22

From the log the original file(YYYXXX.xml) is already deleted by the other process (refer #5) and gives the below error.

Unable to SFTP XML file. Error Message: from PutSFTP: There was an error transferring YYYXXX.xml. Error deleting file 'YYYXXX.xml'. After resumable file upload the existing destination file must be deleted. If you do not have permissions to delete file destination file, you need to disable resumable file transfers. No such file or directory. Error code: 2 Error message from server (en): File not found Request code: 13

Also there is no pattern in the occurrence of this issue i.e not based on file size, date, etc.

We have already included the option confirm off in the script, so resuming should take place as needed. We are using WinSCP Version 5.0.5 (Build 1782).

Is there anything else we need to change/configure ? Let me know what additional info you need from me.

Upvotes: 0

Views: 4061

Answers (1)

Rick S
Rick S

Reputation: 6586

Have you tried using the .NET assembly that you can get as a separate download? I've been using it for a while and it hasn't given me any problems. WinSCP .NET Library

You may also want to look at this bug report : Here

ResumeSupport requires that the .filepart file be written to the ftp site and deleted or renamed. If you don't have permission, you get an error.

The fix is to turn off resume support by updating the WinSCP.ini file and set ResumeSupport=2

More documentation on Resume support here

Upvotes: 2

Related Questions