Operating System - HP-UX
1753515 Members
5476 Online
108795 Solutions
New Discussion юеВ

Execute commands through a ftp session

 
LucianoCarvalho
Respected Contributor

Execute commands through a ftp session

Hi Guys!
Is there anyway to run commands on remote server through a ftp session.
The commands that I wanto to run is tail and head redirectind the outputo to another file.
tail file > output_file
head file > output_file
Thanks
11 REPLIES 11
PIYUSH D. PATEL
Honored Contributor

Re: Execute commands through a ftp session

Hi,

Hi I havent done this thro ftp and I think that it is not possible.

You can do rsh and remsh instead. Go thro
man remsh and rsh.

# rsh -n -l username hostname
tail file > filename

# remsh hostname tail file > filename

# remsh -n -l username hostname
tail file > filename

Piyush
MANOJ SRIVASTAVA
Honored Contributor

Re: Execute commands through a ftp session

Hi Luciana

Not possible by ftp command I have a idea

ftp > !command

command can be

remsh server name tail file > output_file
remsh server name head file > output_file



Manoj Srivastava

Jeff Schussele
Honored Contributor

Re: Execute commands through a ftp session

Hi Luciano,

No, this is not possible, and this is by design. It would be a severe security risk if ftp users could break out of the ftp shell remotely & execute commands on the remote system.

What I would suggest to you is to use "!" to shell out to the local system & run a remsh command to do what you wish on the remote system. Then just exit afterwards & you're still in your ftp session. This way you're not compromising any security features & you're not terminating your ftp session.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!

Re: Execute commands through a ftp session

I'd suggest you "teleport" your files locally
and do whatever you wish, if the files are not to big. Otherwise it its remsh,rcp, uucp, depending of the need
If it ain't rough it ain't me

Re: Execute commands through a ftp session

Always depending of the control you have on both servers, you could define a user that,
when logged, would perform the tail/head operations and ftp the results back!

So in the etc/passwd, instead of a shell path, it'd be the path to script doing the trick

ftp.sh
tail file >output
head file >output
ftp -n -i ftp.log
exit

ftp.cmd would contain
ftp server user passwd
cd favorite_dir
put output there
bye
If it ain't rough it ain't me
W. Michael King
Frequent Advisor

Re: Execute commands through a ftp session

If the SITE EXEC command is enabled, then yes a client can execute commands on the host. Most ftp daemons now have this off by default, I believe.
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." - Benjamin Franklin, Historical Review of Pennsylvania, 1759
LucianoCarvalho
Respected Contributor

Re: Execute commands through a ftp session

Robert,
What is the sintax to run a commando directing the outputo to another file?. I executed the command "SITE EXEC TAIL > OUTPUT_FILE", but it didnt work.
Paula J Frazer-Campbell
Honored Contributor

Re: Execute commands through a ftp session

Hi

On the remote server put a small script to check the existance of a file "go.flag" so that when this file exits it does the tail routines sending the output to a file and then remove the go.flag file and go back to looking for "go.flag".

From the local server ftp to remote, put go.flag (the remote script will now run) and then "get" the results of the tail file.

Simple - no security holes opened.

Paula
If you can spell SysAdmin then you is one - anon
Paula J Frazer-Campbell
Honored Contributor

Re: Execute commands through a ftp session

Hi


tail -n 200 filename > outfile #
tail -n 200 filename >> outfile # Append to file

Will tail the last 200 lines abd redirect the output to outfile.


Paula
If you can spell SysAdmin then you is one - anon