EldoS | Feel safer!

Software components for data protection, secure storage and transfer

UploadFile failing with (error code is 103426) on Xamarin.Android

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#33381
Posted: 05/25/2015 00:44:49
by ECQ Developer (Standard support level)
Joined: 09/03/2014
Posts: 5

When I try to upload a file using TElSimpleSFTPClient.UploadFile I get this error message.

SBCustomFSAdapter.EElVFSAdapterError: File system operation failed with error. Requested path is /data/data/<PackageName>/files/testFile.txt Original error message: (error code is 103426)
at SBCustomFSAdapter.__Global.RaiseVFSAdapterErrorEx (SBCustomFSAdapter.TElCustomFileSystemAdapter Adapter, Int32 ErrorCode, System.String FileName) [0x00065] in <filename unknown>:0
at SBSimpleSftp.TElSimpleSFTPClient.UploadFile (System.String LocalFileName, System.String RemoteFileName, TSBFileTransferMode Mode, Int64 RestartFrom) [0x000d6] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) SBSimpleSftp.TElSimpleSFTPClient:UploadFile (string,string,SBTypes.TSBFileTransferMode,long)
at SBSimpleSftp.TElSimpleSFTPClient.UploadFile (System.String LocalFileName, System.String RemoteFileName, TSBFileTransferMode Mode) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) SBSimpleSftp.TElSimpleSFTPClient:UploadFile (string,string,SBTypes.TSBFileTransferMode)
at <NAMESPACE>.FtpService_Android+<>c__DisplayClass11.<UploadFile>b__10 () [0x00014] in <PATH_TO_CODE>\Services\FtpService_Android.cs:253 } SBCustomFSAdapter.EElVFSAdapterError

I'm using SecureBlackbox SFTP v12.0.26 and have added the dlls
SecureBlackbox.dll
SecureBlackbox.SFTP.dll
SecureBlackbox.SFTPCommon.dll
SecureBlackbox.SSH.dll
SecureBlackbox.SSHCommon.dll

from C:\Program Files (x86)\EldoS\SecureBlackbox.NET\Assemblies\Xamarin.Android of my SecureBlackbox installation. It appears to relate to file access from my searching, but I have confirmed the file is there. I can also see the connection has been made to the sftp server.

Any help would be greatly appreciated.

Thanks,
Lyall.
#33382
Posted: 05/25/2015 01:12:14
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

The error code stands for SB_VFS_ERROR_FILE_NOT_FOUND. Its possible that file is on its place, but can't be opened for some reason. Could you check if you can open this file? Also you should check if needed permissions like android.permission.READ_EXTERNAL_STORAGE are set in project settings.
#33383
Posted: 05/25/2015 01:22:32
by ECQ Developer (Standard support level)
Joined: 09/03/2014
Posts: 5

Thank you for the quick reply.

I've tried opening the file again as soon as I've written it and that works for me.

The code I'm using to read/write the files is very basic c#

File.WriteAllText (filePath, text); and
File.ReadAllText (filePath);

I've also got reading and writing from SQLite databases happening in my application which are stored in the same location and that it working well for me.
#33387
Posted: 05/25/2015 02:28:26
by Eugene Mayevski (EldoS Corp.)

Please create the FileStream from your file and pass it to UploadStream() method instead of UploadFile(). This will eliminate your problem completely. Also this seems to be faster than to determine, what exactly didn't work in your case. Still if you are interested in making UploadFile() work, please let us know and we'll provide additional instructions.


Sincerely yours
Eugene Mayevski
#33388
Posted: 05/25/2015 02:35:57
by ECQ Developer (Standard support level)
Joined: 09/03/2014
Posts: 5

Thank you Eugene,

I have done this and the uploaded file is working using the UploadStream() method. Because I'm reading the file back again this is more code for me to write and maintain, so if there is a fairly straight forward way to make the UploadFile() code work that would be nice unless you really don't recommend using it?

Thanks,
Lyall
#33389
Posted: 05/25/2015 02:45:16
by Eugene Mayevski (EldoS Corp.)

Modifications in your code are just two extra lines of code - one to open the stream and another one to close it after uploading of the stream.

As for UploadFile - this issue is specific to your environment and we will need to reproduce the problem, but this can be non-trivial.

Can you please specify
a) exact version of SecureBlackbox that you are using (you've written "12.0.26" but this one is missing the last digit which is important).
b) the exact value which you pass as the local file name?


Sincerely yours
Eugene Mayevski
#33404
Posted: 05/25/2015 18:59:20
by ECQ Developer (Standard support level)
Joined: 09/03/2014
Posts: 5

I'm not sure how I missed it but the version is 12.0.269

The file I am opening is /data/data/Ecq.ECL.ELMO/files/testFile.txt
however the issue is the same for /mnt/sdcard/Download/testFile.txt

Also something which might be the cause of of the problem is I'm having trouble opening a stream to the file even outside of SecureBlackBox. I can read the file using ReadAllText, but not open a stream to the file.

Thank you,
Lyall.
#33406
Posted: 05/25/2015 23:43:43
by Eugene Mayevski (EldoS Corp.)

Quote
ecq_dev wrote:
Also something which might be the cause of of the problem is I'm having trouble opening a stream to the file even outside of SecureBlackBox. I can read the file using ReadAllText, but not open a stream to the file.


Yes, this is the primary problem. Neither SecureBlackbox nor your own code can open the stream.

You have two options here:
1) a simple one is to write all data which you read with ReadAllText to the instance of MemoryStream, then upload this MemoryStream
2) contact Xamarin support (or Xamarin community) for assistance in opening the file stream. We don't have enough experience with Xamarin to answer why the file can't be opened. This can be Xamarin-specific issue, especially as ReadAllText works.


Sincerely yours
Eugene Mayevski
#33427
Posted: 05/26/2015 21:06:17
by ECQ Developer (Standard support level)
Joined: 09/03/2014
Posts: 5

Thanks you for all your help on this issue Eugene. I'm not 100% sure what I saw yesterday that made me think I couldn't open a stream from my own code, but today I have tried to reproduce it to request help on the Xamarin forums and opening the stream to read is working perfectly.

I'm even able to read from the stream using the following code:
Code
// Read the source file into a byte array.
            var bytes = new byte[stream.Length];
            var numBytesToRead = (int)stream.Length;
            var numBytesRead = 0;
            while (numBytesToRead > 0)
            {
               // Read may return anything from 0 to numBytesToRead.
               int n = stream.Read(bytes, numBytesRead, numBytesToRead);

               // Break when the end of the file is reached.
               if (n == 0)
                  break;

               numBytesRead += n;
               numBytesToRead -= n;
            }

            Debug.WriteLine("Read file");
            Debug.WriteLine(System.Text.Encoding.UTF8.GetString(bytes,0,bytes.Length));

However when I pass the stream object into SftpClient.UploadStream() I get the following exception:
Quote

SBSftpCommon.EElSFTPError: Permission denied.
at SBSftp.TElSftpClient.OpenFileSync (System.String Filename, Int32 Modes, SBSftpCommon.TElSftpFileAttributes Attributes) [0x00043] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) SBSftp.TElSftpClient:OpenFileSync (string,int,SBSftpCommon.TElSftpFileAttributes)
at SBSimpleSftp.TElSimpleSFTPClient.OpenFile (System.String Filename, Int32 Modes, SBSftpCommon.TElSftpFileAttributes Attributes) [0x00016] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) SBSimpleSftp.TElSimpleSFTPClient:OpenFile (string,int,SBSftpCommon.TElSftpFileAttributes)
at SBSimpleSftp.TElSimpleSFTPClient.UploadStream (System.IO.Stream LocalStream, System.String RemoteFileName, TSBFileTransferMode Mode, Int64 RestartFrom) [0x001d2] in <filename unknown>:0


As you mentioned I'm able to read the data into a memory stream and pass that in so I am able to upload information, but only that approach is currently working of the various functions available.

Thanks,
Lyall.
#33429
Posted: 05/26/2015 23:45:42
by Eugene Mayevski (EldoS Corp.)

Permisson Denied error is returned by the SFTP server. Most likely you have specified the value for Remote file name in the form, which doesn't lead to the intended destination.

The only correct form is /path/to/filename.ext (note the leading slash). This tells the server where to put the file and how to name it. Specifying only the path without a filename won't work. Specifying the filename without a path or without a leading slash will make the server construct a path starting from the user's home directory (which is probably not what you expect).


Sincerely yours
Eugene Mayevski
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

Topic viewed 1652 times

Number of guests: 1, 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!