Is it possible to run a program through FTP prompt?

6

I'm relatively new to Unix or shell scripting (a total novice to speak the truth), here is the deal: I have BI software that runs on a remote UNIX server. Through SAS client on Windows i run some analytic and create some flat files that need to be automatically pushed to that UNIX server, that's no problem through the SAS X command to execute Unix commands on rsubmit, I upload the files throught FTP prompt however i want to use a "sh " command once I logged on the ftp server

ftp -nv << -EOF > /AutomatedReports/Flatfiles/log/sendInv.log
open biserver.myserver.com
user biuser pass1234
prompt
lcd  /container/AutomatedReports/KPI_Flatfiles/
cd  /container/AutomatedReports/apps/flatfiles
put kpi_new_inv.txt
put instock_trend.txt
quit

The code above is sent to UNIX, however when I include

sh edastart -x "EX test"

i get an error, I just want to know if Im doing something wrong so I can look for another way to do it. Any help, guidance or answer will be highly appreciated.

isJustMe

Posted 2011-10-27T13:51:27.030

Reputation: 197

Answers

5

No, you cannot start a program on a distant Unix server using FTP protocol (unless you use some bizarre extensions of it).

Why cannot you use ssh, that is copy the file to the distant Unix server using scp, and then login into that server using ssh.

Basile Starynkevitch

Posted 2011-10-27T13:51:27.030

Reputation: 1 022

1http://www.chiark.greenend.org.uk/~sgtatham/putty/ is a SSH client for Windows. – None – 2011-10-27T14:00:51.220

thanks, I do have putty installed on the computer, but the thing is I want to automate that process (the sas program runs on a scheduled task) so pretty much i do everything on it and the manually execute the remote script from putty which is precisely what I want to avoid, from SAS i can execute dos commands or batch files though, is there a way I could execute it if putty is isntalled on my machine? – None – 2011-10-27T14:03:39.243

1

If you could execute arbitrary commands, that would be a gross security breach in the FTP server. FTP is a file transfer method only; for remote execution, turn to SSH instead.

Fred Foo

Posted 2011-10-27T13:51:27.030

Reputation: 985

I see... thanks for letting me know that.. is there a way to execute a shell script from windows (with authentication) without installing a third-party tool? – None – 2011-10-27T13:57:57.187

@Rafael.IT: not that I know of. Grab Putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/ and prey that an SSH server is installed on the remote host. While you're at it, switch from FTP to SFTP to get secure file transfer.

– Fred Foo – 2011-10-27T14:03:16.930

Thanks I do have putty on my machine, and the there is a SSH server on the remote host, thats how I execute the shell scripts remotely, but I need to automate this process... any suggestions? – None – 2011-10-27T15:30:16.860

1

Do it over shell with putty like others said. If you need to automate the process why not set up a cron job and/or a trigger file?

chris

Posted 2011-10-27T13:51:27.030

Reputation:

cron jobs are on unix side, I have to automate it on windows side – None – 2011-10-27T17:15:19.593

1

I do exactly this to execute a Hive query on a remote linux host, and have the results piped back to my SAS program. If there is no output from your SAS code then it's still a good idea to collect any STD output as you can then perform a check to make sure it all ran ok.

filename hive pipe 'C:\Progra~1\ICW\bin\ssh.exe server.name.local -l username -i c:\id_rsa " ls "' lrecl=80;

data x ;
  length line $80.;
  infile hive truncover;
  input @1 line $80.;
run;

The 3rd party executable I used can be found here:

http://www.itefix.no/i2/copssh

I generated an RSA key so I wouldn't have to supply my full credentials at each login but I'm sure you'll be able to figure that out, or just supply a regular username password as parameters...

Note that you could also execute the above remote command using the SAS 'X' command if you didn't want to pipe any results back.

Good luck R

Rob Penridge

Posted 2011-10-27T13:51:27.030

Reputation: 111

1

Look into using TCL/Expect. The Expect module to TCL excels at automating console commands, including handling login prompts and passwords and ftp commands. With an Expect script, you can automate a complete ftp login session. Anything you can do manually you can do via Expect. You basically tell the shell what command to execute, and what prompt or response to "expect". What you expect can be specified as a hard coded value or as a regular expression. One example of using Expect is to script an automated test for logging into a Cisco router (userid/password), configuring the router, running some tests, verifying the results, then exiting out of the router.

vc_virginia

Posted 2011-10-27T13:51:27.030

Reputation: 11

0

If you're already familiar with PuTTY then use Plink, from the same developer. It supports remote execution of commands over SSH, and can be used in automated scripts.

Alex

Posted 2011-10-27T13:51:27.030

Reputation: 1