DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

PuTTY connection

Tue Jul 31, 2018 9:27 am

Hi,

I am using PuTTY to connect to an RPï zero, via, Win 10, vb.net, USB, like so:

Dim sftp As New SftpClient(hostA.local", "pi", "raspberry")
sftp.Connect()
'remote file we want to read
Dim s As String = sftp.ReadAllText("/home/pi/text.txt")
MessageBox.Show(s)
sftp.Disconnect()

This works great.

I also have a "Host B" and a "Host C", all RPi zeroes with USB connections.
Every minute or so, i need to retrieve the content of the text file that is created by the Pi zeroes.
The question is, should i connect and disconnect evry time, or should/can i leave the connections open,
all 3 at the same time ?

thx,
Paul

User avatar
Mortimer
Posts: 925
Joined: Sun Jun 10, 2012 3:57 pm

Re: PuTTY connection

Tue Jul 31, 2018 11:36 am

I don't know quite what you're trying to do.

But from the sounds of it, you are just retrieving a text file from each of the three Pis.

I would either:

(1) If the Win10 PC is on all the time, create a shared folder and have the Pis use Samba to write the text files directly into the share, then the PC doesn't have to go get them at all.

(2) Create Samba shares on the Pis, and have the PC get the files from those shared folders.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: PuTTY connection

Tue Jul 31, 2018 3:12 pm

Wow, Samba ?

Are you referring to the dance moves or is that a piece of software ?
I'll see if I can find it .

thx,
Paul

User avatar
Mortimer
Posts: 925
Joined: Sun Jun 10, 2012 3:57 pm

Re: PuTTY connection

Tue Jul 31, 2018 3:28 pm

I can do Samba, my wife is Brazilian and a good dance teacher, however : What is Samba
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: PuTTY connection

Tue Jul 31, 2018 3:39 pm

From what i understand, after reading some stuff about samba, i fail to see how that is going to be "better" than the Putty solution.
But, i may be wrong.

This is what i am doing:
- Start Putty session on win 10
- Connect via USB to 3 pi zeroes (that simultaneous question is still my original topic starter)
- Those pi zeroes are assembled to be input terminals, where numbers are inputted, written to a txt file.
- Every minute i run a visual studio program on the desktop, that collects the data in those txt files.
- Those data are processed and projected on a screen.

What could samba do to improve this setup ?

thx,
Paul

Ernst
Posts: 1326
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: PuTTY connection

Tue Jul 31, 2018 4:34 pm

DPaul wrote:
Tue Jul 31, 2018 3:39 pm
From what i understand, after reading some stuff about samba, i fail to see how that is going to be "better" than the Putty solution.
But, i may be wrong.

This is what i am doing:
- Start Putty session on win 10
Why ?
- Connect via USB to 3 pi zeroes (that simultaneous question is still my original topic starter)
How ?
- Those pi zeroes are assembled to be input terminals, where numbers are inputted, written to a txt file.
What ? How ? Why ?
- Every minute i run a visual studio program on the desktop, that collects the data in those txt files.
What desktop ? Collect how ?
- Those data are processed and projected on a screen.
Where ? What screen ?
What could samba do to improve this setup ?
It depends on your answers.

If you give good answers to the above questions somebody will surely be able to give you some advice,
at the moment it does not make sense why you start Putty to connect via USB because Putty uses the network.
I could try to guess but that may make the situation more confused.
The road to insanity is paved with static ip addresses

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: PuTTY connection

Tue Jul 31, 2018 5:18 pm

I'm sure there is a misunderstanding here, everything should be clear with these lines:

Dim sftp As New SftpClient(hostA.local", "pi", "raspberry") : this is set up with PuTTY, 3 times for 3 zeroes: HostA, HostB, HostC are their names
sftp.Connect()
'remote file reading (also 3 times for 3 zeroes)
Dim s As String = sftp.ReadAllText("/home/pi/text.txt") : here is where i read the contents of the text file(s)
(MessageBox.Show(s) : this symbolises the processing which is of course more complicated.)
sftp.Disconnect()

This works perfectly.

Would samba do this better?, there are only 4 lines of code in vb.net, and none on the RPi zeroes.

Not more difficult than this.
Paul

User avatar
Mortimer
Posts: 925
Joined: Sun Jun 10, 2012 3:57 pm

Re: PuTTY connection

Tue Jul 31, 2018 5:38 pm

I'm not understanding how PuTTY fits into this.
SFTP just needs an SFTP client on the Windows machine and an SFTP service running on the Pis.
It looks like you're using the SSH.NET library.

As the connections are secure, I see no reason to close the connections between reads for security reasons. Performance wise, I can't imaging there is a significant difference either way.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: PuTTY connection

Wed Aug 01, 2018 6:34 am

OK, i am using the SSH library on the laptop and nothing on the Pi zero.
I have to use something, to create the 3 connections.

As response times are important, i thought it better not to have any extra software running on the pi.
I can use pi 3b 's, but that makes the project much more expensive.

Closing or not closing the connection: OK i can time how long it takes.

The question remains, will it work with 3 connections open simultaneously?
Why don't i test that ?
Well i have assembled the first terminal, and wrote a python program for it.
That works.
Before i assemble 2 or more extra terminals, i would like to have some
indication that it will run for hours without a problem or performance degradation.
I have no experience with writing networking apps.

Paul

markkuk
Posts: 196
Joined: Thu Mar 22, 2018 1:02 pm
Location: Finland

Re: PuTTY connection

Wed Aug 01, 2018 6:56 am

DPaul wrote:
Wed Aug 01, 2018 6:34 am
OK, i am using the SSH library on the laptop and nothing on the Pi zero.
You must have the sshd service running on the Pi Zeros.
DPaul wrote:
Wed Aug 01, 2018 6:34 am
I have to use something, to create the 3 connections.
The Visual Basic code you have posted twice creates the connections. There's no need to create additional connections with PuTTY, they have no effect on running the VB program.

Ernst
Posts: 1326
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: PuTTY connection

Wed Aug 01, 2018 6:57 am

DPaul wrote:
Wed Aug 01, 2018 6:34 am
OK, i am using the SSH library on the laptop and nothing on the Pi zero.
I have to use something, to create the 3 connections.

As response times are important, i thought it better not to have any extra software running on the pi.
I can use pi 3b 's, but that makes the project much more expensive.

Closing or not closing the connection: OK i can time how long it takes.

The question remains, will it work with 3 connections open simultaneously?
Why don't i test that ?
Well i have assembled the first terminal, and wrote a python program for it.
That works.
Before i assemble 2 or more extra terminals, i would like to have some
indication that it will run for hours without a problem or performance degradation.
I have no experience with writing networking apps.

Paul
1) You are using a PC, in that case using pscp (https://www.chiark.greenend.org.uk/~sgt ... atest.html) is much simpler.
2) You do not need to assemble "terminals" if you are using pscp
3) You can run multiple pscp sessions between two systems
4) pscp does encryption and authorization.
5) but if you really want to use sftp then you can also use psftp
The road to insanity is paved with static ip addresses

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: PuTTY connection

Wed Aug 01, 2018 8:17 am

Before I get totally confused:

1. https://www.chiark.greenend.org.uk/~sgt ... atest.html
This is where i downloaded putty.
I have difficulty imagining anything simpler :-)

I start putty, give the 3 host adresses (I can even save them, so no typing)
I can start the monitoring program on the zeroes via putty, once and leave them running.
The zeroes shut down by themselves, when i type a "secret code" on the terminal keypad.

They are assembled terminals because they are designed to capture a specific kind of events.
Each terminal is manned by a different person who captures the data by keypad, with some input validation going on etc...

2. Maybe i can do without putty. The fact of plugging the zero via usb into the PC, creates a connection.
I have not figured out how yet.

3.Perhaps i should take a look at "psftp"., but i do not need encryption, authorisation...etc. This is a closed system, totally under my control.
I could dream of additional features, by intervening on the Zeroes from the PC at specific moments. But then KISS.

Paul

Ernst
Posts: 1326
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: PuTTY connection

Wed Aug 01, 2018 9:45 am

DPaul wrote:
Wed Aug 01, 2018 8:17 am
Before I get totally confused:

1. https://www.chiark.greenend.org.uk/~sgt ... atest.html
This is where i downloaded putty.
I have difficulty imagining anything simpler :-)

I start putty, give the 3 host adresses (I can even save them, so no typing)
I can start the monitoring program on the zeroes via putty, once and leave them running.
PuTTY uses the ssh protocol on the Pi0 to start a terminal session. When you start a program over ssh this program will be terminated if the connection is terminated (for any reason). To ensure that the program keeps running can use nohup.
With PuTTY you can use keys so that you do not need to login to the Pi0.
The zeroes shut down by themselves, when i type a "secret code" on the terminal keypad.
Do you shut down the Pi0 or do you terminate your program ?
They are assembled terminals because they are designed to capture a specific kind of events.
Each terminal is manned by a different person who captures the data by keypad, with some input validation going on etc...
That implies that you capture information.
2. Maybe i can do without putty. The fact of plugging the zero via usb into the PC, creates a connection.
I have not figured out how yet.
In other words, you want to use ethernet gadget mode on the Pi0 to be able to connect via the network to the Pi0.
Are you aware that the distance is limited to the maximum length of the USB cable ?
Are you aware that these will be point to point connections, you will have multiple ethernet interfaces on your computer.
3.Perhaps i should take a look at "psftp"., but i do not need encryption, authorisation...etc. This is a closed system, totally under my control.
ftp is a primitive file transfer protocol, sftp is a "secure" ftp using ssh, psftp is the PuTTY supplied PC version of sftp client. ftp requires user interaction. The following example does not ask for password because it is using my keys.

Code: Select all

C:\Users\Ernst>psftp [email protected]
Using username "pi".
Remote working directory is /home/pi
psftp> get readme.txt
remote:/home/pi/readme.txt => local:readme.txt
psftp> exit

C:\Users\Ernst>
scp is a file copy program, pscp is the PuTTY supplied PC version of scp, WinSCP is a Windows GUI version of scp. scp can be run from the command line without user interaction. The following two examples show how to transfer from the command line, the second transfer in quiet mode to suppress statistics, both using my keys.

Code: Select all

C:\Users\Ernst>pscp [email protected]:readme.txt .
readme.txt                | 0 kB |   0.0 kB/s | ETA: 00:00:00 | 100%

C:\Users\Ernst>pscp -q [email protected]:readme.txt .

C:\Users\Ernst>
The largest effort with programming is error and exception detection and recovery, with PuTTU (putty, plink, psftp, pscp) most of the work is done already and you can wrap these programs in your own application.
I could dream of additional features, by intervening on the Zeroes from the PC at specific moments. But then KISS.
A very simple method to intervene is to have your program look for a file, you can use the name of the file or the contents of the file. In this example the program looks for a file named "STOP" in the home directory which is created from the command line on the PC.

Code: Select all

C:\Users\Ernst>plink [email protected] touch STOP

C:\Users\Ernst>plink [email protected] ls -l STOP
-rw-r--r-- 1 pi pi 0 Aug  1 11:39 STOP

C:\Users\Ernst>
The road to insanity is paved with static ip addresses

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: PuTTY connection

Wed Aug 01, 2018 10:46 am

Some good ideas there:

1. No need for USB cables longer than 150 cm.
2. I stop the zeros (secret code) as "sudo shutdown -h now"
3. I do not actually copy a file from the Pi0 's, i read the files ,
and transform the content into varables for further processing on the PC.
4 . I do nothing in command mode on the PC, everything from code vb.net
5. The idea of intervening on the Pi0 by creating a file with a special name has crossed my mind,
but have not figured out yet what sfpt.xxxxx command that would be.
Then i would need the Pi0 (python) to monitor that "arrival".
6. Will try to find examples of the pscp stuff

Paul

Return to “Beginners”