EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Error Code 2 in SFTP

Posted: 12/29/2008 09:56:25
by Brian Mahocker (Standard support level)
Joined: 12/29/2008
Posts: 4

I'm attempting to upload a file using SFTP version 6.1.149, and intermittently receive and error code of 2 within the SftpClient_OnError handler.

The error occurs on a call to .UploadFile(). I've not been able to find any pattern to the error, but if I try uploading the file again 5 minutes, 20 minutes, or 2 hours later, it will often work, but not always.

Error 2 indicates "SSH_ERROR_NO_SUCH_FILE A reference is made to a file which does not exist. " (from the help file), but I have verified multiple times that the local file does exist, and the remote file does not exist.

Is there any other condition that could cause this error message, or some other information about the error I could find?


SftpClient.Address = GetSingleMiscValue("CitiGroupFTPSite")
SftpClient.Username = GetSingleMiscValue("CitiGroupFTPUsername")
SftpClient.Password = GetSingleMiscValue("CitiGroupFTPPassword")
SftpClient.Port = 22
SftpClient.AuthenticationTypes = SftpClient.AuthenticationTypes And Not SBSSHConstants.Unit.SSH_AUTH_TYPE_PUBLICKEY


If SftpClient.Active
   shortName = System.IO.Path.GetFileName(FilePath)
   SftpClient.UploadFile(FilePath, shortName)
End If

Posted: 12/29/2008 10:18:25
by Ken Ivanov (Team)

Thank you for contacting us.

First of all, it is necessary to detect the exact request that causes the error (UploadFile() performs several requests internally, such as file existence and size checks). Please do the following:
(a) put a breakpoint inside the OnError event handler,
(b) when execution flow stops on the breakpoint, please copy the call stack to the clipboard and paste it here.
Posted: 12/29/2008 14:26:44
by Brian Mahocker (Standard support level)
Joined: 12/29/2008
Posts: 4

Call stack displayed below:

>   SMI_BackEnd.exe!SIRVA.Imaging.frmBackEnd.SftpClient_OnError(Object Sender = {SBSimpleSftp.TElSimpleSFTPClient}, Integer ErrorCode = 2) Line 1143   Basic
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.DoError(System.Object Sender = {SBSSHClient.TElSSHClient}, int ErrorCode = 2) + 0x6d bytes   
   secureblackbox.sshcommon.dll!SBSSHCommon.TElSSHClass.DoError(int ErrorCode = 2) + 0x29 bytes   
   secureblackbox.sshclient.dll!SBSSHClient.TElSSHClient.SSH2ParseServerDisconnect(byte[] Buffer = {Length=263168}, int Size = 87) + 0x180 bytes   
   secureblackbox.sshclient.dll!SBSSHClient.TElSSHClient.SSH2ParseOnTransportLayer(byte[] Buffer = {Length=263168}, int Size = 87) + 0x2ae bytes   
   secureblackbox.sshclient.dll!SBSSHClient.TElSSHClient.AnalyseBuffer() + 0x83d bytes   
   secureblackbox.sshclient.dll!SBSSHClient.TElSSHClient.DataAvailable() + 0x1a1 bytes   
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.DataAvailable() + 0x58 bytes   
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.IntMessageLoop() + 0xf bytes   
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.DoMessageLoop() + 0x15 bytes   
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.HandleSftpMessageLoop() + 0x10 bytes   
   secureblackbox.sftp.dll!SBSftp.TElSftpClient.Write(byte[] Handle = {Length=1}, long Offset = 0, byte[] Buffer = {Length=131072}) + 0xe8 bytes   
   secureblackbox.sftp.dll!SBSftp.TElSftpClient.WriteSync(byte[] Handle = {Length=1}, long Offset = 0, byte[] Buffer = {Length=131072}) + 0x53 bytes   
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.Write(byte[] Handle = {Length=1}, long Offset = 0, byte[] Buffer = {Length=262144}, int StartIndex = 0, int Count = 262144) + 0xe7 bytes   
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadStream(System.IO.Stream LocalStream = {System.IO.FileStream}, string RemoteFileName = "FTP_001120508661_32593.zip", SBSftpCommon.TSBSFTPFileTransferMode Mode = ftmOverwrite, long RestartFrom = -1) + 0x4e1 bytes   
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadFile(string LocalFileName = @"\\FWA-NETAPP02A\IMGFILES\MORT\LenderSend\CITI\FTP_001120508661_32593.zip", string RemoteFileName = "FTP_001120508661_32593.zip", SBSftpCommon.TSBSFTPFileTransferMode Mode = ftmOverwrite, long RestartFrom = -1) + 0x75 bytes   
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadFile(string LocalFileName = @"\\FWA-NETAPP02A\IMGFILES\MORT\LenderSend\CITI\FTP_001120508661_32593.zip", string RemoteFileName = "FTP_001120508661_32593.zip", SBSftpCommon.TSBSFTPFileTransferMode Mode = ftmOverwrite) + 0x20 bytes   
   secureblackbox.sftp.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadFile(string LocalFileName = @"\\FWA-NETAPP02A\IMGFILES\MORT\LenderSend\CITI\FTP_001120508661_32593.zip", string RemoteFileName = "FTP_001120508661_32593.zip") + 0x1b bytes   
   SMI_BackEnd.exe!SIRVA.Imaging.frmBackEnd.ConnectAndUpload(String FilePath = "\\FWA-NETAPP02A\IMGFILES\MORT\LenderSend\CITI\FTP_001120508661_32593.zip") Line 1117 + 0x1d bytes   Basic
   SMI_BackEnd.exe!SIRVA.Imaging.frmBackEnd.ProcessCitiGroup() Line 524 + 0xe bytes   Basic
   SMI_BackEnd.exe!SIRVA.Imaging.frmBackEnd.LookForFile() Line 348 + 0xb bytes   Basic
   SMI_BackEnd.exe!SIRVA.Imaging.frmBackEnd.Timer1_Tick(Object sender = {System.Windows.Forms.Timer}, System.EventArgs e = {System.EventArgs}) Line 381 + 0xb bytes   Basic
   system.windows.forms.dll!System.Windows.Forms.Timer.OnTick(System.EventArgs e = {System.EventArgs}) + 0x1f bytes   
   system.windows.forms.dll!System.Windows.Forms.Timer.DebuggableCallback(int hWnd = 0, int msg = 275, int idEvent = 15558, int dwTime = 24636562) + 0x2d bytes   
   system.windows.forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(int dwComponentID = 1, int reason = -1, int pvLoopData = 0) + 0x358 bytes   
   system.windows.forms.dll!ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x1f5 bytes   
   system.windows.forms.dll!ThreadContext.RunMessageLoop(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x50 bytes   
   system.windows.forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm = {SIRVA.Imaging.frmBackEnd}) + 0x34 bytes   
   SMI_BackEnd.exe!SIRVA.Imaging.frmBackEnd.Main() Line 12 + 0x1d bytes   Basic
Posted: 12/29/2008 23:58:41
by Ken Ivanov (Team)

The error you are getting is not an SFTP error, but an SSH protocol error. It is likely that the server does not understand one of transfer parameters. Please try the following steps to resolve the problem:
a) set AutoAdjustTransferBlock property to true and check if it resolves the issue,
b) if (a) does not help, please set AutoAdjustTransferBlock to false, PipelineLength to 1 and try again,
c) if neither (a) nor (b) works, please provide us the name of the server-side software (can be retrieved via the ServerSoftwareName property) for deeper investigation of the issue.
Posted: 01/05/2009 02:11:19
by goubin dylan (Standard support level)
Joined: 09/19/2006
Posts: 13


any news on this issue that also affects us ?
Posted: 01/05/2009 05:00:16
by Ken Ivanov (Team)

Have you tried the above three steps? Did one (or more) of them work for you?
Posted: 01/05/2009 07:58:14
by Brian Mahocker (Standard support level)
Joined: 12/29/2008
Posts: 4


So far, it seems to be working for us. We've only had two or three batches go through this application, and so far, they've all worked fine. Of course, with such few examples, I can't say if it is 'randomly' working, or working because of this fix.

I'll let it run for another week, and give you an update.

Thanks for the info.

Posted: 01/07/2009 13:17:22
by Brian Mahocker (Standard support level)
Joined: 12/29/2008
Posts: 4

So far, we've run about a dozen batches through with your code changes in place (option (b) in the previous posts), and it seems to be working flawlessly again.

Thanks muchly for the information.

Posted: 08/28/2014 08:39:11
by Steve Cote (Standard support level)
Joined: 08/23/2012
Posts: 1

I ran into a similar problem and thought I'd post my findings to help others. In my case the behavior was that I'd call UploadFile() and it would return with no error, except that the connection was lost, so subsequent file operations would result in an exception that I could "see".

In the end, the problem for me was the SFTP server was not configured to default me into the account's home folder.

The return code of "2" wasn't helpful as mentioned in this thread because the error was actually an SSH error, not SFTP.

I found two articles that were particularly helpful:

This first article suggested running the sample code to see if that works, which it did... hmmm. The second article pinpointed exactly what my issue was. Citing Case 2, I invoked the RequestAbsolutePath("/") method and voila... 8 hours, 1 line of code, and 2 Mountain Dews later it was working.

I also implemented an event handler that would catch this error in the future instead of letting TElSimpleSFTPClient continue (SFTPException is a custom exception I created for my project):

private void sftpClient_OnError(object sender, int errorCode)
   throw new SFTPException(
      String.Format("An error occurred (code {0}) causing the server connection to close.  Reason: {1}",
              HostAddress = SFTPConnection.Address,
              Port = SFTPConnection.Port,
              Username = SFTPConnection.Username,
              ClientPrivateKeyId = SFTPConnection.ClientPrivateKeyId,
              ServerPublicKeyId = SFTPConnection.ServerPublicKeyId

Delegate the event handler like this:
TElSimpleSFTPClient sftpClient = new TElSimpleSFTPClient()
sftpClient.OnError += new TSSHErrorEvent(sftpClient_OnError);



Topic viewed 5345 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!