Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 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.

share|improve this answer
    
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 Sep 1 '11 at 15:25
1  
@Shlublu No problem, glad if it helps! –  OldWolf Sep 1 '11 at 15:36
up vote 1 down vote accepted

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
    
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.