473,412 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Background process for ssh port forwarding

Hello all,

I'm writing a script which will backup data from my machine to a server
using rsync. It checks to see if I am on the local network. If I am, it
runs rsync over ssh to 192.168.2.6 using the pexpect module to log in.
That's the easy part.

Now, when I'm not on the local network, I first want to open up an ssh
connection to do port forwarding, so something like this:

def hostforward():
#This is based on the assumption that the passfile is the gnus
#authinfo file, or has a similar format...
f = open(PASS_FILE, "r")
f_list = f.read().split(' ')
f.close()
#Now, we get the entry after "password" (be slicker to make it a
#dictionary, but maybe wouldn't work as well).
pass_index = f_list.index('password') + 1
forwardpass = f_list[pass_index]
#now we connect
command = 'ssh -l %s -L 2022:%s:22 %s' % \
(login, my_server, forwarding_server)
connection = pexpect.spawn(command)
connection.expect('.*assword:')
connection.sendline(forwardpass)

If I end this with 'connection.interact()', I will end up logged in to the
forwarding server. But what I really want is to go on and run rsync to
localhost port 2022, which will forward to my_server port 22. So, how can
I put the ssh connection I set up in hostforward() in the background?
I need to make sure that connection is made before I can run the rsync
command.

I've looked at threading, but that seems excessive. There must be an
easier way. Whatever I do, though, I'll need to use pexpect to spawn the
processes, since I'll need to log in to ssh servers with a password.

Thanks for any help.

--Jesse
Nov 22 '05 #1
0 1911

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
0
by: md | last post by:
Hi, I'm trying to run a stored procedure with linked servers on Sql2k over a broadband connection where sql server is setup for port forwarding and am getting the error :- Server: Msg 7391,...
1
by: Jesse Rosenthal | last post by:
Hello all, I'm writing a script which will backup data from my machine to a server using rsync. It checks to see if I am on the local network. If I am, it runs rsync over ssh to 192.168.2.6...
0
by: Adam Clauss | last post by:
As the built in interface for forwarding ports in Windows 2003 Routing and Remote Access has several 'difficiencies' (like the ability to forward a RANGE of ports), I would like to write an...
25
by: bmearns | last post by:
Is it possible to specify which port to use as the outbound port on a connection? I have the IP address and port number for the computer I'm trying to connect to (not listening for), but it's...
10
by: lavida | last post by:
Hi All I was looking for how to read barcodes in background from a wifi reader using VB6. my barcode scanner is a wifi reader. When reading, does the incoming data goes to the COM port? even if...
8
by: Ravi | last post by:
Hi to all, There is a start button in my page. if user clicks on that then a php program should start and should listen on a particular port. and also user should able to do other tasks on...
0
by: Bradley Plett | last post by:
I need to build a small "port forwarder" that will check some security settings before allowing traffic through. Can anyone suggest a good component for doing the port forwarding? Alternatively,...
1
by: nileshNP | last post by:
Hi I have a question. I have to create a tunnel between two systems X and Y, X behind NAT and Y is public. There are two programs Px - running on X and Py-running on Y. I am first establishing a...
4
by: ethangk | last post by:
Hey This is a little hard to explain but I will try my best. Is it possible to have a application running on a specific computer on a network, and to have all requests sent from the internet sent to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.