Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » SFTP or full SSH2 support for U++? (Discussion about implementing the SSH2 protocol using libssh2)
Re: SSH2 wrapper for U++ [message #48880 is a reply to message #48879] Thu, 19 October 2017 15:09 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello Tom,


Quote:
I downloaded this latest version now after using the version from a few months back.

In order to successfully compile the code, I had to comment out the entire contents of SFtpMT.cpp and the following lines in SFtp.h:

AsyncWork<String> SFtpGet(SshSession& session, const String& path, Gate<int64, int64> progress = Null);
AsyncWork<void> SFtpGet(SshSession& session, const String& source, const String& target, Gate<int64, int64> progress = Null);




Ah yes, that's because I use U++ trunk (latest nightly builds).
In case you didn't notice, there is now a class called AsyncWork in U++ core, which is a MT helper. Those functions use that. Smile


Quote:


Then there's one question: Now that the names have changed, is there a replacement for session.IsSuccess() ? (I just removed these calls in my code to see if SFTP still works. It did Smile )



You don't need it. I got rid of the old ones. There is only IsError(). Smile

You can use the IsError() method to check success when it is necessary.

Did you look into the provided SFtpDemo app? Take a look into it. It demonstartes the basic usage pattern for SFtp (same pattern is valid for other components too)

If you use blocking mode, then you can simply check the return code (IsError will be still available though.)

In non-blocking mode, A successful operation means there is no error. So again, you can simply check IsError(), and then get the result with GetResult() method if the invoked method returns a value.

By the way, GetResult() method is needed in non-blocking mode for such methods as FileExists(), for we need to separate the state of operation (failure/success) from the return value of operation.

Non-blocking:

void GetFileSize(SshSession& session)
{
	DLOG("---- Getting file size of " << file << " (non-blocking):");
	auto sftp = session.CreateSFtp();
	sftp.NonBlocking().GetSize(file);
	while(sftp.Do())
		Sleep(1);
	if(sftp.IsError())
		DDUMP(sftp.GetErrorDesc());
	else
		DDUMP((int64) sftp.GetResult());	// In non-blocking mode, results can be
							// "harvested" using GetResult() method.
}

void FileExists(SshSession& session)
{
	DLOG("---- Test if " << file << " exists (non-blocking):");
	auto sftp = session.CreateSFtp();
	sftp.NonBlocking().FileExists(file);
	while(sftp.Do())
		Sleep(1);
	if(sftp.IsError())
		DDUMP(sftp.GetErrorDesc());
	else
		DDUMP((bool) sftp.GetResult());

        // Alternatively (blocking)
        if(sftp.NonBlocking(false).FileExists(file))
           Cout() << file << " exists.\n";
        else
           Cerr() << sftp.GetErrorDesc() << '\n'; 
}
.


Blocking:
	DLOG("---- Downloading file " << file << " directly to Cout() (blocking):");
	auto sftp = session.CreateSFtp();
	if(!sftp.Get(file, Cout()))
		DDUMP(sftp.GetErrorDesc());
	else
		DLOG("Done.");


Or

void GetDirectoryList(SshSession& session)
{
	DLOG("---- Getting directory listing of " << dir << " (blocking):");
	auto sftp = session.CreateSFtp();
	SFtp::DirList list;
	if(sftp.ListDir(dir, list)) { 
		for(auto& e : list)
			DDUMP(e);				     
	}
	else DDUMP(sftp.GetErrorDesc());
}



I'll explain the details in documentation, but it is really very simple.

Note that I "removed" also the batch processing mode. This new version of SSH package can only process one request at a time. (well, from the user POV, at least. Basically it still uses a queue, but only internally, and in a well-determined way)

Best regards,
Oblivion


[Updated on: Thu, 19 October 2017 16:05]

Report message to a moderator

Re: SSH2 wrapper for U++ [message #48886 is a reply to message #48880] Mon, 23 October 2017 08:29 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Oblivion,

Thanks for explaining the new details. I did not read the SFtpDemo this time, since I had already implemented client calls in my own software. So in effect I was just updating the SFTP code to its latest version. I should have paid more attention to the changes.

Anyway, thanks for the update! I'll let you know if I run into any trouble with it.

Best regards,

Tom
SSH package for U++ (alpha version) [message #48964 is a reply to message #45813] Mon, 13 November 2017 21:25 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello,

SSH package is updated.
This version is the first "alpha" release.

This version brings,

- Multithreading support for SFtp, Scp, and SshExec classes.

- Ssh agent authentication support.

- SocketWaitEvents support for non-blocking I/O

- Ssh known hosts support (re-added).

- API documentation (updated)

- SFtp::DirEntry class gained ToXml() method. 

- Keyboard (challenge/response) authentication (re-added)

- Updated libssh2

- Various bugfixes


I will soon add SshShell support. In fact there is already a prototype of SshShell for Posix based OSes. It can execute remote commands in real-time, and allows using editors such as nano, vim, emacs on console. It also works with GUI. Smile I will add it once I clean its source code.

However, adding shell support on windows is somewhat tricky (at least, adding a console (CLI) based version is not so trivial, for standard I/O handling is different on windows. I need to find a reliable way before I can include it in the pacakge, so it'll take some time...)


I set up a GIT repo some time ago, where you can find the latest versions of my public U++ packages:

https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH

Below you can find the latest package. (I will open a Bazaar topic from the next release on, and update the package regularly.)

It is tested on Linux and Windows (GCC/MINGW 7.2, MSC 14 (2017)).


Suggestions, criticism, bug reports, reviews, testing is always welcome,

Cheers!

Oblivion


[Updated on: Mon, 13 November 2017 21:32]

Report message to a moderator

Re: SFTP or full SSH2 support for U++? [message #48967 is a reply to message #45813] Tue, 14 November 2017 08:03 Go to previous messageGo to next message
alkema_jm is currently offline  alkema_jm
Messages: 25
Registered: November 2015
Promising Member
index.php?t=getfile&id=5432&private=0LS,

I use upp-win-11459.7z, vs2017 and Windows10 , I downloaded https://svn.code.sf.net/p/ultimatecomponents/svn/, I put the trunk directories in the bazaar directory.

IpAddrInfo addrinfo;

Error is that the variable 'addrinfo' is a type/structure in Ultimate. To solve error, is renaming variable 'addrinfo' in something else for example 'addrinfo2'.


Re: SFTP or full SSH2 support for U++? [message #48968 is a reply to message #48967] Tue, 14 November 2017 08:38 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Quote:

alkema_jm
index.php?t=getfile&id=5432&private=0LS,

I use upp-win-11459.7z, vs2017 and Windows10 , I downloaded https://svn.code.sf.net/p/ultimatecomponents/svn/, I put the trunk directories in the bazaar directory.

IpAddrInfo addrinfo;

Error is that the variable 'addrinfo' is a type/structure in Ultimate. To solve error, is renaming variable 'addrinfo' in something else for example 'addrinfo2'.


Hello alkema_jm,

Thank you for notifiying me about the issue.

SVN repo is not yet updated. SSH package in SVN repo is outdated. I will update it tonight.

https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH

However, the name clash you've mentioned is already fixed in the GIT version above.

Note that the new version is not entirely compatible with the old one. I suggest you update to it.
It is a re-write with a much better design with a ton of bug-fixes and new features. (Transition should be fairly easy though),

Ps.My previous message also includes the latest zip file which contains an example code demonstrating the basic usage of the latest SSH package. You may want to chech that too.

Best regards,
Oblivion




[Updated on: Tue, 14 November 2017 08:45]

Report message to a moderator

Re: SFTP or full SSH2 support for U++? [message #48969 is a reply to message #48968] Tue, 14 November 2017 11:57 Go to previous messageGo to next message
alkema_jm is currently offline  alkema_jm
Messages: 25
Registered: November 2015
Promising Member
Hello Oblivion,

I put the code in my C:\dev\upp\bazaar directory. I use each time fresh upp-win-11459.7z (source files), vs2017 and Windows10 See for the results the screendumps below.

Greetings Jan Marco

index.php?t=getfile&id=5433&private=0

[Updated on: Tue, 14 November 2017 12:04]

Report message to a moderator

Re: SFTP or full SSH2 support for U++? [message #48970 is a reply to message #48969] Tue, 14 November 2017 12:41 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello Jan Marco,

Thank you very much for feedback. Smile
Warnings aside (they are not really important here and will be addressed soon),

Quick fix for SFtpDemo: You can make SFtpDemo work by changing SFtpGet to SFtp::AsyncGet (in SFtpDemo.cpp, at line 83)

Other error messages: SSH, Job, NetProxy and FTP packages are 3rd party U++ libraries, and they are meant to be used in applications or other libraries.
That's why you are getting linker errors about _main.

Best regards,
Oblivion


[Updated on: Tue, 14 November 2017 13:01]

Report message to a moderator

Re: SFTP or full SSH2 support for U++? [message #48971 is a reply to message #48970] Tue, 14 November 2017 14:27 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Oblivion,

Thanks for the update. I just downloaded it and compiled it in and it still works just fine within my app. (That is for the SFTP part I'm using Smile

Thanks and best regards,

Tom
Re: SFTP or full SSH2 support for U++? [message #48972 is a reply to message #48971] Tue, 14 November 2017 21:51 Go to previous message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello Tom,

I am glad that it works for you. Smile


Since SSH package has now passed the technical-preview stage, and has a mostly stable API, I am opening a new topic on the Bazaar section and officially announcing it as a SSH supplement for Ultimate++ core library.

From now on you can always find latest version, help, and SSH package-related news there:

https://www.ultimatepp.org/forums/index.php?t=msg&th=101 72&start=0&

Best regards,
Oblivion


[Updated on: Tue, 14 November 2017 22:00]

Report message to a moderator

Previous Topic: Help needed with link errors (serversocket)
Next Topic: Ultimate++ repo and chat?
Goto Forum:
  


Current Time: Thu Mar 28 12:11:14 CET 2024

Total time taken to generate the page: 0.01582 seconds