EldoS | Feel safer!

Software components for data protection, secure storage and transfer

ElSftpClient Put/Get file sample code or outline

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#13185
Posted: 05/04/2010 14:31:19
by Greg  (Standard support level)
Joined: 12/09/2009
Posts: 20

Hello all,

I'm attempting to use the ElSftpClient class (not the simple one) to build my app. I've got it connecting (no errors at least) but I don't see any code behind the get and put of the sophisticated client so I'm not sure of the steps I should use to get and put files. I've scoured the help file, online knowledgebase and the forums looking for an example piece of code, or an outline of steps to follow. No luck finding that so far.

I've got the sftpclient open. What is it that I should be doing next?

Since I'm working on sending a file (receive is next) do I need to check for existance of the file & how would I do that? Then I suppose the next step is the creatfile. Do I open a handle to the correct directory first? Do I just start writing with reference to the created handle?

How do you handle things like failures at either end? How do I know the file got there "ok"?. When is the file available for pickup by the remote end? do I need to do some sort of a close? Do I need to do any locking?

As you can see, I have a tonne of questions.

Thanks for the fine product,
-greg
#13186
Posted: 05/04/2010 15:03:12
by Eugene Mayevski (EldoS Corp.)

I am not sure that I understand your problem.

Did you check SophisticatedClient sample? It answers most (if not all) of your questions.


Sincerely yours
Eugene Mayevski
#13187
Posted: 05/04/2010 15:12:27
by Ken Ivanov (EldoS Corp.)

BTW, do you actually have a reason for using the TElSFTPClient class? TElSimpleSFTPClient is a more convenient and easy-to-use solution for most of the use cases. One of the few exceptions when usage of TElSFTPClient is justified is the need to maintain several logical SSH channels of different types (e.g. shell + SFTP).
#13188
Posted: 05/04/2010 15:14:20
by Greg  (Standard support level)
Joined: 12/09/2009
Posts: 20

Greetings Eugene,

Yes, I looked at the sophisticated client. As I noted, there is no code behind the get and put buttons (nothing hooked to any event in either button) in the sample I have. There is lots of other code there, but the starting point seems to be missing. I have run the app, I can connect, list directories and the like, but I can't get or put anything as nothing is connected to the buttons.

What should be connected to the click events of those buttons?

-greg
#13189
Posted: 05/04/2010 15:21:03
by Greg  (Standard support level)
Joined: 12/09/2009
Posts: 20

Hello Innokentiy,

I have used the simple client on the first version. I found that I had problems with connects and such hanging due to errors and things never timing out. I now have the ability to cleanly timeout my connections without having to resort to a timer thread for each activity (can be hundreds).

Additionally, I would like a better understanding of what it takes to do SSH and SFTP without having to write real low level code. Writing to your SftpClient gives me a bit more exposure in this area.

Thanks for your interest!

-greg
#13190
Posted: 05/04/2010 15:22:34
by Ken Ivanov (EldoS Corp.)

Unfortunately, the VB.NET SophisticatedClient demo has not been completed for some reason. We are sorry for disappointing you. Hope that the C# version of this sample will help you in your investigations.
#13191
Posted: 05/04/2010 15:28:55
by Ken Ivanov (EldoS Corp.)

Quote
I found that I had problems with connects and such hanging due to errors and things never timing out. I now have the ability to cleanly timeout my connections without having to resort to a timer thread for each activity (can be hundreds).

Hmm, have you reported the issues you faced here to the forum or to the Helpdesk? TElSimpleSFTPClient is a highly-configurable class, so I suppose that the issues could be fixed with certain properties adjustments performed.

Quote
Additionally, I would like a better understanding of what it takes to do SSH and SFTP without having to write real low level code. Writing to your SftpClient gives me a bit more exposure in this area.

That's why we recommend using TElSimpleSFTPClient wherever possible. This class encapsulates all the work with low-level objects. Besides, it contains a number of workarounds for well-known third-party implementations bugs.
#13192
Posted: 05/04/2010 16:29:16
by Greg  (Standard support level)
Joined: 12/09/2009
Posts: 20

Hot Dawg!

Yes, the C# will do fine. I can read the stuff well enough to figure out what I need to do. I didn't even think to go look at the C# code, but there it is, just what I was looking for!

The low level code I was talking about would be to write the code to do SSH and SFTP itself. That's just too ugly to contemplate at this stage of my life. You have the product that does what I need without me having to reinvent that particular wheel.

I still want to understand the interactions between TCP/SSH/SFTP/what-have-you without having to do the lowest level coding myself. The Simple is too high-level for this purpose.

One intersting thing see in your reply is the handling for "quirky" third-party implementations. Even with the simple, I see some quirky issues with some custom servers. One in particular names it's root directory <virtual directory> and getting that one to work required some experimentation.

Some of the hangs I've had aren't due to the (eldos) code, but have been things like servers getting hung up, disappearing mid-stream and just otherwise failing. Most just throw an error but sometimes it hangs. Since this is esentially un-monitored software, it will stick for hours or days until somebody notices. I'm looking to start an action, wait on a waithandle for an appropriate amount of time and if I timeout then close/dispose the connection and related processes and schedule a restart for the activity that failed.

Another hang I've had has been for some component of our internal SAN fabric going bye-bye or a server where a file is stored going poof. These cause hangs as well.

I do have a watchdog thread working in this newer re-write and plan on using it to detect hangs and cancelling whatever is going on in the hanging task as a means of recovery. Still, I'm interested in delving deeper to this whole process.

-greg
#13211
Posted: 05/06/2010 01:11:29
by Ken Ivanov (EldoS Corp.)

SecureBlackbox SFTP implementation includes two sets of components that can be used on two different abstraction levels:
1) Low-level components:
- TElSSHClient, TElSSHTunnelList, TElSubsystemSSHTunnel are responsible for SSH layer of the connection,
- TElSFTPClient is responsible for SFTP layer of the connection,
- TElSocket is responsible for TCP layer. You can use any third-party network components as well.
2) TElSimpleSFTPClient is a high-level component which encapsulates all the TCP, SSH and SFTP layers by binding the low-level components to work together.

As I already said above, we recommend using TElSimpleSFTPClient class for general SFTP tasks.

Quote
One intersting thing see in your reply is the handling for "quirky" third-party implementations. Even with the simple, I see some quirky issues with some custom servers. One in particular names it's root directory <virtual directory> and getting that one to work required some experimentation.

The exact names of root or home directories do not matter for SFTP clients. SFTP provides two general abilities for browsing server-side file system:
1) a possibility to use special "." and ".." directories referring to the current directory and the directory one level above, and a "/" path separator character,
2) a possibility to perform a server-side conversion of relative path to an absolute one.

An example. Say, you wish to download a "text.txt" file from a $HOME/files/ directory. First, you should call a RequestAbsolutePath() method to get an absolute path to the needed file:
string absPath = Client.RequestAbsolutePath("./files/text.txt");
Second, you have to pass the obtained path to the DownloadFile() method.

As you can notice, the above method does not require you to know the specifics of server-side file system and the way it names its root directory.

Regarding the hangups, TElSimpleSFTPClient provides a mechanism for detecting socket timeouts (the SocketTimeout property). You can use this one to make the component throw an exception if no data has been received from the remote for a certain period of time.
#13230
Posted: 05/06/2010 14:00:21
by Greg  (Standard support level)
Joined: 12/09/2009
Posts: 20

Greetings Innokentiy,

Thank you for your reply. That information will help.

The hangs are usually in the connect. I suspect it's because Microsoft doesn't seem to offer a connect timeout on it's stuff. I've tried the ontimeout and related and it didn't work for connections.

Anyway, I'm getting the error "SFTP component not connected" so I must not be doing a part of the prepatory work correctly. I've included what I have without any error trapping, event handlers or other structure.

Currently my sequence is this:
_Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
_SocketAsyncEA = New SocketAsyncEventArgs
_SocketAsyncEA.RemoteEndPoint = HostEndPoint
AddHandler _SocketAsyncEA.Completed, AddressOf OnConnectAsyncComplete
_Socket.ConnectAsync(_SocketAsyncEA)

_SSHClient = New TElSSHClient
_SSHClient.Versions = SBSSHCommon.Unit.sbSSH2
_SSHClient.AuthenticationTypes = <clipped, too long>
_SSHClient.UserName = SRProtocol.UserID
_SSHClient.Password = SRProtocol.Password
<AddHandlers clipped>

_SSHTunnel = New TElSubsystemSSHTunnel

_SSHTunnelList = New TElSSHTunnelList
_SSHClient.TunnelList = _SSHTunnelList
_SSHTunnel.TunnelList = _SSHTunnelList

_SFTPClient = New TElSftpClient
_SFTPClient.Tunnel = _SSHTunnel
<AddHandlers clipped>

_SSHClient.Open()

All of the above works without any errors or faults and I think I have the connection open and ready for SFTP traffic. However, when I try the next statement, I get the "SFTP component not connected" message.

_SFTPClient.CreateFile(RemoteFileName) <-- error thrown here


So, I figure I didn't connect something correctly, but I don't know what.

Thanks,
-greg
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 7708 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!