1834162 Members
2890 Online
110064 Solutions
New Discussion

Re: FTP within a script

 
SOLVED
Go to solution
Marie Eldridge_1
Occasional Contributor

FTP within a script

I am trying to create a script that will ftp orders to another machine whenever the order is created. I figured I would set it up as a cron job for checking. My problem is I don't know how to execute a command within a script. It stops at ftp and waits for input from the keyboard. When I quit the command it executes the rest of the script.

Thanks for your help.
10 REPLIES 10
Andreas Voss
Honored Contributor
Solution

Re: FTP within a script

Hi,

try:

ftp -n <open
user
get ....
put...
bye
EOF

Regards
James R. Ferguson
Acclaimed Contributor

Re: FTP within a script

Hi:

There are lots and lots of posts in this forum to show you different ways to do this. Do a search on 'ftp'. Here are some just to start you off!

http://my1.itrc.hp.com/cm/QuestionAnswer/1,1150,0xe0830559ff7cd4118fef0090279cd0f9,00.html

http://my1.itrc.hp.com/cm/QuestionAnswer/1,1150,0x00517e990647d4118fee0090279cd0f9,00.html

...JRF...

Kofi ARTHIABAH
Honored Contributor

Re: FTP within a script

There have been a number of very good threads on this subject ... you can do a search on with the SEARCH button at the top left.. (with the keywords script ftp) to get you started:

http://my1.itrc.hp.com/cm/QuestionAnswer/1,1150,0x19587e990647d4118fee0090279cd0f9,00.html
http://my1.itrc.hp.com/cm/QuestionAnswer/1,1150,0xe0830559ff7cd4118fef0090279cd0f9,00.html
http://my1.itrc.hp.com/cm/QuestionAnswer/1,1150,0xf4677e990647d4118fee0090279cd0f9,00.html
nothing wrong with me that a few lines of code cannot fix!
Paula J Frazer-Campbell
Honored Contributor

Re: FTP within a script

Hi this format will automate you ftp, just fill in the details and put an entry in your crontab for when.
________________cut_____________
ftp -n (IP ADRESS) << End_of_Ftp
user (LOGIN) (PASSWORD)
prompt
mput (FILENAMES)
#or
put (FILENAME)
quit
End_of_Ftp
________________cut_____________

Best wishes
If you can spell SysAdmin then you is one - anon
BONNAFOUS Jean Marc
Trusted Contributor

Re: FTP within a script

You can also use a command like this:

ftp -i -n < "ftpfilename"

where filename is a file with ftp command like:

open "HOSTNAME"
users USERS PASSWD
...
...
bye


Be sure what USERS has ftp authorization.
Si vous ne faites jamais de bétises, c'est que vous ne faites rien de difficile. Et ça c'est une grosse bétise.
Fred Martin_1
Valued Contributor

Re: FTP within a script

I use something like this on HP-UX 10.20

# ftp to NT server to get the report
#
(
echo "open 000.000.000.000"
echo "user anonymous from_script"
echo "ascii"
echo "get checkfab.txt"
echo"bye"
) | ftp -i -n
fmartin@applicatorssales.com
Wodisch
Honored Contributor

Re: FTP within a script

Oh Marie,

please, read the man-page. I am getting really sick of those "scripts" trying
to control the ftp session with input redirection...
Create a file "$HOME/.netrc" and put in something like:

machine 1.2.3.4 user fred password secret macdef init
bin
cd /target-dir
lcd /source-dir
prompt
mput *
quit

Attention: there must be an empty line after this paragraph.
Next time your start "ftp" and point it to station "1.2.3.4", it
will start transfering all files from your local directory "/source-dir"
to the directory "/target-dir" on station "1.2.3.4" using binary
transfer.
The macro "init" will be automatically started after logging in
on the target station.

HTH,
Wodisch
Tim Nelson
Honored Contributor

Re: FTP within a script

I have found on occasion when the ftp servers are slow or connectivity is slow that the input to EOF gets out of sync. The "expect" scripting language will allow for 'wait for' prompting. This software is available on the HP software porting and archive center site.
Ralph Grothe
Honored Contributor

Re: FTP within a script

Just as a (probably idle) addition to the last responder,
in case you aren't particularily fond of TCL/Expect (like me ;-) but rather are into Perl, there is a nice CPAN module Net::FTP for automating FTP sessions.
But then I guess, you would probably know.
Type "perldoc Net::FTP" to find out if it's installed on your box.
As to the posters with the "Here File" solutions ("<For instance, the ~/.netrc thing wouldn't work unless the file is solely readable to the owner, for that reason.
But as others already mentioned consult the ftp manpage.
Madness, thy name is system administration
Marie Eldridge_1
Occasional Contributor

Re: FTP within a script

Thanks for your help. There were lots of great suggestions.