Solaris equivalent of the Cygwin or Windows command "ftp -s:batch_cmd_file"

0

I am using a FTP script that runs under Cygwin and Windows cmd and that uses the ftp's -s command-line switch to read and execute commands from a batch file:

ftp -i -s:/path/ftp.params 

The batch file ftp.param is generated by another job and contains standard FTP commands such as:

OPEN my_address
my_login
my_password
GET file_a
GET file_b
BYE

Now I have to use this ftp script under Solaris, but according to its ftp man page, the Solaris version of ftp doesn't accept the command-line switch -s to execute a batch file.

I've searched in that doc, and also on the web, but I did not find the way to go. Do you have any suggestion?

Shlublu

Posted 2011-09-01T13:40:37.520

Reputation: 113

Answers

1

Ok, I have found a solution that works.

Basically, instead of opening the remote ftp site from the batch file, I have to open it from the ftp command and then to use the shell to feed ftp with the batch file. As I'm always using the same ftp address I can live with it.

The only real drawback is that this requires modifying the batch file a bit, so the job that generates it.

  • The shell part consists in executing the ftp command the following way:

    ftp -i -n my_address < /path/ftp.params
    
  • And the batch file should be modified that way:

    USER my_login my_password 
    GET file_a
    GET file_b
    BYE
    

Shlublu

Posted 2011-09-01T13:40:37.520

Reputation: 113

2

That option seems to only be available to the windows ftp client. For a similar result, you can install an ftp client that you can script. NcFTP is pretty friendly to this. Wget would work too.

With ncftp, you'd have a file with your "get" list and one with your login credentials if you don't want to enter them every time. (Be aware of the security risks involved)

From the command line using bash you'd either enter the following into a script or just run:

while read line
do
    ncftpget -f <FILEWITHCREDENTIALS> $line -bb
done < <FILEWITHLIST>
ncftpbatch -d

Your credentials file will be in the form of

host <my_address>
user <my_login>
pass <my_password>

-bb submits each file as a batch job waiting to run. Calling ncftpbatch will run the job. Doing this should limit it to one connection.

Other options would be -b (just kick the job off in the background immediately) and dropping the ncftpbatch call, and using the user/host/password options in the command instead of -f.

You can find ncftp here and here if it's not already installed.

For wget you can use a similar looping script and replace the ncftpget call with

wget ftp://user:password@ftp.mydomain.com/path/$line

again, if it's not already installed, you can get wget here or for with either program look up the appropriate package manager for your version of Solaris.

You can find more information about the programs with the man pages or through a quick web search.

OldWolf

Posted 2011-09-01T13:40:37.520

Reputation: 2 293

Thanks @OldWolf! I'm going to have a look at that. Even though I finally find a working solution, yours may be more flexible and is also interesting to me for other tasks not related to this topic. – Shlublu – 2011-09-01T15:25:15.617

1@Shlublu No problem, glad if it helps! – OldWolf – 2011-09-01T15:36:57.470