LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-22-2004, 12:19 PM   #1
doza
Member
 
Registered: Jan 2004
Distribution: Redhat
Posts: 31

Rep: Reputation: 15
Connect to remote server and initiate FTP


The project that I am working on right now requires a script/program to connect to a remote server and initiate an FTP from that server to yet another server. We have a central server that we would like to run all of our scripts and cron jobs from. The file that needs to be transferred, however, must originate from a separate machine. Is there a way that I can do this?

Something like:
Cron job on server A connects to server B
Server B then runs a script to grab a file
Server B then FTP's file to server C

What's the easiest way to do this? Can the connection from A to B be encrypted (ssh?)?

Thanks
 
Old 06-22-2004, 03:31 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
You can do it this way: script from machine A uses ssh to conect to B and uses ftp to upload a file to C. If you configure ssh to use public-private keys (with no password need) it'd be quite easy in a script.

Last edited by Mara; 06-22-2004 at 03:34 PM.
 
Old 06-22-2004, 03:31 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
(mistake: quote instead of edit...)

Last edited by Mara; 06-22-2004 at 03:35 PM.
 
Old 06-22-2004, 04:00 PM   #4
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
to further what Mara said, you can execute a command through ssh. for example:

ssh user@SERVERB '(cd /etc; cat fstab)'

will ssh in, do the stuff in quotes, and log out. So... if you setup public key authentication, from server A, you coud simply:

ssh SERVERB 'ncftpput -u user -p passwd -S .tmp -V -m SERVERC dest_dir file'

assuming "file" lives on SERVERB. If it doesn't, you can tar over ssh as well, and in the same ssh session as the untar, you could execute the ncftpput command

There are other alternatives to ncftpput... I believe there's ftpupload (Debian based) and... well, I'm sure several others.

edit: I'll go ahead and give you the tar command in case you need it - it would be something like (assuming the script and file were on SERVERA:

tar cf - file | ssh user@SERVERB '(cd /some_dir; tar xf -; ncftpput -options SERVERC dest_dir file)'

Last edited by BrianK; 06-22-2004 at 04:04 PM.
 
Old 06-23-2004, 11:16 AM   #5
doza
Member
 
Registered: Jan 2004
Distribution: Redhat
Posts: 31

Original Poster
Rep: Reputation: 15
Wow, thanks for all the help. That should work perfectly.

That tar command was pretty slick too.

Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
connect to remote x server blas Linux - General 8 09-29-2005 04:20 AM
how to connect remote by ftp by graphically.. bruse Linux - Networking 2 04-08-2005 12:17 PM
Unable to connect to remote server Suresh Chowta Linux - Networking 1 02-13-2005 06:29 AM
ssh to initiate process on remote machine jdarren Linux - Networking 3 03-23-2004 05:55 PM
how can i connect to a remote X server? likid0 Linux - Software 1 07-11-2003 01:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration