EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SFTP UploadFile SSH Error

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#26297
Posted: 09/04/2013 09:18:10
by Jesse Terrell (Standard support level)
Joined: 05/29/2007
Posts: 24

I have an error using the SimpleSFTP client attempting to upload a file to an SFTP server. I can connect fine but when attempting to upload a file I always receive an error code 2 in the "OnError" event. I've searched the knowledge base and forums and tried everything I found there.

I've been using SecureBlackBox 9.x and am now using the RC for version 11 in hopes this error will go away but I obviously have a setting wrong somewhere because version 11 (RC) won't auto adjust to this SFTP server for me.

The server to which I'm trying to upload a file is: Maverick_SSHD

The c# code I'm executing is:

Code
...
// Tried combinations of these per other posts in the forums
Client.AutoAdjustTransferBlock = false;
Client.PipelineLength = 1;
Client.DownloadBlockSize = 4096;
...
Client.UploadFile( @uncFilePath, absPath, SBUtils.TSBFileTransferMode.ftmSkip );


I'm beginning to suspect that because the UploadFile command always attempts to create the target folder, and we don't have that permission on the server, that the call is failing. Not really sure how to keep UploadFile from attempting to create the target folder, or even if this could be the issue.

The Call Stack in the OnError event is below. If anyone has any thoughts on what particular client setting I need to flip for this ridiculous Maverick_SSHD server I would be forever grateful!

Code
>   EDeeInboundService.exe!EDeeInboundService.InboundService.sshClient_OnError(object Sender, int ErrorCode) Line 2757   C#
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.DoError(object Sender, int ErrorCode) + 0xa4 bytes   
   SecureBlackbox.SSHCommon.dll!SBSSHCommon.TElSSHClass.DoError(int ErrorCode) + 0x68 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.SSH2ParseServerDisconnect(byte[] Buffer, int Size) + 0x217 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.SSH2ParseOnTransportLayer(byte[] Buffer, int Size) + 0x424 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.AnalyseBuffer() + 0x1421 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.DataAvailable() + 0x245 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.DataAvailable() + 0xba bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.IntMessageLoop() + 0x30 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.DoMessageLoop() + 0x3c bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.HandleSftpMessageLoop() + 0x30 bytes   
   SecureBlackbox.SFTP.dll!SBSftp.TElSftpClient.RequestAttributes(string Path, bool FollowSymLinks) + 0x18e bytes   
   SecureBlackbox.SFTP.dll!SBSftp.TElSftpClient.RequestAttributesSync(string Path, bool FollowSymLinks) + 0xa0 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.RequestAttributes(string Path, bool FollowSymLinks, SBSftpCommon.TElSftpFileAttributes Attributes) + 0xc0 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadStream(System.IO.Stream LocalStream, string RemoteFileName, SBUtils.TSBFileTransferMode Mode, long RestartFrom) + 0x1e6 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadFile(string LocalFileName, string RemoteFileName, SBUtils.TSBFileTransferMode Mode, long RestartFrom) + 0x150 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadFile(string LocalFileName, string RemoteFileName, SBUtils.TSBFileTransferMode Mode) + 0x57 bytes   
   EDeeInboundService.exe!EDeeInboundService.InboundService.doSFTPOut(EDeeInboundService.InboundService.TradingPartner tradingPartner) Line 932 + 0x49 bytes   C#
   EDeeInboundService.exe!EDeeInboundService.InboundService.doWork() Line 337 + 0x2b bytes   C#
   mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x285 bytes   
   mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x9 bytes   
   mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x57 bytes   
   mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x51 bytes   
   [Native to Managed Transition]   
#26299
Posted: 09/04/2013 10:10:00
by Eugene Mayevski (EldoS Corp.)

The server doesn't like RequestAttributes command for the file. This command is sent to determine whether the file exists when you set the mode to Skip. Setting the transfer mode to Overwrite will let you skip RequestAttributes. So you can check file existence before calling UploadFile, then set TransferMode to stmOverwrite.

Normally the server should return File Not Found error (which it does) and continue the session (which is does not). In other words, the server erroneously closes connection.


Sincerely yours
Eugene Mayevski
#26300
Posted: 09/04/2013 10:17:03
by Jesse Terrell (Standard support level)
Joined: 05/29/2007
Posts: 24

Eugene,
Thank you for the quick response!! However, I have tried the TransferMode set to Overwrite. Actually that is our default setting and I only changed it to "Skip" in desperation trying combinations that might upload to this server. My apologies for not stating that in the original post.
By chance do you have any other ideas that we may try? Would it be helpful to see the call stack with the Overwrite setting? Any advice you can offer would be much appreciated.
#26301
Posted: 09/04/2013 10:25:25
by Eugene Mayevski (EldoS Corp.)

Of course we need a stack trace that is relevant to the original problem.


Sincerely yours
Eugene Mayevski
#26302
Posted: 09/04/2013 10:38:53
by Jesse Terrell (Standard support level)
Joined: 05/29/2007
Posts: 24

Eugene,
The devil's in the details! Thanks for your help on this. Here is code:
Code
Client.UploadFile( @uncFilePath, absPath, SBUtils.TSBFileTransferMode.ftmOverwrite);


Here is the call stack:
Code
>   EDeeInboundService.exe!EDeeInboundService.InboundService.sshClient_OnError(object Sender, int ErrorCode) Line 2756   C#
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.DoError(object Sender, int ErrorCode) + 0xa4 bytes   
   SecureBlackbox.SSHCommon.dll!SBSSHCommon.TElSSHClass.DoError(int ErrorCode) + 0x68 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.SSH2ParseServerDisconnect(byte[] Buffer, int Size) + 0x217 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.SSH2ParseOnTransportLayer(byte[] Buffer, int Size) + 0x424 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.AnalyseBuffer() + 0x1421 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.DataAvailable() + 0x245 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.DataAvailable() + 0xba bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.IntMessageLoop() + 0x30 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.DoMessageLoop() + 0x3c bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.HandleSftpMessageLoop() + 0x30 bytes   
   SecureBlackbox.SFTP.dll!SBSftp.TElSftpClient.RequestAttributes(string Path, bool FollowSymLinks) + 0x18e bytes   
   SecureBlackbox.SFTP.dll!SBSftp.TElSftpClient.RequestAttributesSync(string Path, bool FollowSymLinks) + 0xa0 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.RequestAttributes(string Path, bool FollowSymLinks, SBSftpCommon.TElSftpFileAttributes Attributes) + 0xc0 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.CreateRemoteFolder(string Path) + 0xd8 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadStream(System.IO.Stream LocalStream, string RemoteFileName, SBUtils.TSBFileTransferMode Mode, long RestartFrom) + 0x500 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadFile(string LocalFileName, string RemoteFileName, SBUtils.TSBFileTransferMode Mode, long RestartFrom) + 0x150 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.UploadFile(string LocalFileName, string RemoteFileName, SBUtils.TSBFileTransferMode Mode) + 0x57 bytes   
   EDeeInboundService.exe!EDeeInboundService.InboundService.doSFTPOut(EDeeInboundService.InboundService.TradingPartner tradingPartner) Line 930 + 0x46 bytes   C#
   EDeeInboundService.exe!EDeeInboundService.InboundService.doWork() Line 337 + 0x2b bytes   C#
   mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x285 bytes   
   mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x9 bytes   
   mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x57 bytes   
   mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x51 bytes   
   [Native to Managed Transition]   
#26303
Posted: 09/04/2013 10:46:42
by Eugene Mayevski (EldoS Corp.)

Well, the reason is the same - bugs in the server. Folder creation doesn't take place if the folder exists, but the client does check for folder existence (always). The problem is that folder creation call is wrapped with try/catch in order to handle buggy situations, but we can't turn it off. I think we will need to add some option to not check anything before uploading or downloading. I've added this to the todo list, but so far the only solution would be to use OpenFile/WriteFile/CloseHandle sequence of methods instead of simple Uploadfile.


Sincerely yours
Eugene Mayevski
#26304
Posted: 09/04/2013 10:51:42
by Eugene Mayevski (EldoS Corp.)

There's one thing you need to check:

Please try a call to SFTPClient.OpenFile() and pass it your destination name. It's possible that the problem is not [just] with the server but also with your code passing wrong destination file path (eg. no filename included).


Sincerely yours
Eugene Mayevski
#26305
Posted: 09/04/2013 11:42:08
by Jesse Terrell (Standard support level)
Joined: 05/29/2007
Posts: 24

Eugene,
Here is the OpenFile call with a test file while connected to that troublesome SFTP server. Do you see anything that might be helpful for us as a workaround for our problem?

Code
byte[] fileHandle;
fileHandle = Client.OpenFile(@"\\fileserver\Outbound\test.txt", SBSftpCommon.Unit.fmRead, SBSftpCommon.Unit.faReadLock, null);
Client.CloseHandle(fileHandle);


Code
>   EDeeInboundService.exe!EDeeInboundService.InboundService.sshClient_OnError(object Sender, int ErrorCode) Line 2762   C#
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.DoError(object Sender, int ErrorCode) + 0xa4 bytes   
   SecureBlackbox.SSHCommon.dll!SBSSHCommon.TElSSHClass.DoError(int ErrorCode) + 0x68 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.SSH2ParseServerDisconnect(byte[] Buffer, int Size) + 0x217 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.SSH2ParseOnTransportLayer(byte[] Buffer, int Size) + 0x424 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.AnalyseBuffer() + 0x1421 bytes   
   SecureBlackbox.SSHClient.dll!SBSSHClient.TElSSHClient.DataAvailable() + 0x245 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.DataAvailable() + 0xba bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.IntMessageLoop() + 0x30 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.DoMessageLoop() + 0x3c bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.HandleSftpMessageLoop() + 0x30 bytes   
   SecureBlackbox.SFTP.dll!SBSftp.TElSftpClient.OpenFile(string Filename, int Modes, int Access, SBSftpCommon.TElSftpFileAttributes Attributes) + 0x15a bytes   
   SecureBlackbox.SFTP.dll!SBSftp.TElSftpClient.OpenFileSync(string Filename, int Modes, int Access, SBSftpCommon.TElSftpFileAttributes Attributes) + 0xc5 bytes   
   SecureBlackbox.SFTP.dll!SBSimpleSftp.TElSimpleSFTPClient.OpenFile(string Filename, int Modes, int Access, SBSftpCommon.TElSftpFileAttributes Attributes) + 0xba bytes   
   EDeeInboundService.exe!EDeeInboundService.InboundService.doSFTPOut(EDeeInboundService.InboundService.TradingPartner tradingPartner) Line 934 + 0x32 bytes   C#
   EDeeInboundService.exe!EDeeInboundService.InboundService.doWork() Line 337 + 0x2b bytes   C#
   mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x285 bytes   
   mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x9 bytes   
   mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x57 bytes   
   mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x51 bytes   
   [Native to Managed Transition]   
#26307
Posted: 09/04/2013 12:18:55
by Eugene Mayevski (EldoS Corp.)

Of course, this path is not valid for the server.
SFTP servers usually accept Unix-style paths which are either relative to user's home directory or absolute, eg. /path/to/filename.ext . What you have passed is not a valid file in vast majority of cases.


Sincerely yours
Eugene Mayevski
#26308
Posted: 09/04/2013 12:37:46
by Jesse Terrell (Standard support level)
Joined: 05/29/2007
Posts: 24

Eugine,
I have never used that OpenFile command and incorrectly assumed it would open a local file on our network and that another command would push the local filt to the remote server. From your reply it appears the OpenFile command opens a target file on the remote server and then the Write command pushes data to that new file via the file handle.
In any case, the UploadFile command we use is syntactically correct and we do use a Unix naming convention for the target file on the remote server. The UploadFile command works perfectly for many other remote Unix servers with which we trade data.
When time permits I'll experiment further with using the OpenFile/Write/CloseHandle idea you indicated to write our file to the remote server.
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 2153 times

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




|

Back to top

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

Got it!