Basic bash -- pulling files from an FTP server

Hi guys. Very new to this so apologies if this is ridiculously obvious, but I am not sure why this isn't working. I want to pull a file off an FTP server. I currently do it through windows, which is no problem, but I want to move everything to a Linux box I just installed. wget won't work as the remote directory isn't part of the root directory as defined in the FTP server.

The script is as below. It connects to the ftp, but just sits at the ftp> prompt and goes no further. I do not know why it isn't sending the username and password and completing the script? Can anyone shed any light? I've googled and it seems like it should work...?

#!/bin/bash
ftp -inv 172.17.1.1
quote user login password
bin
prompt off
cd /opt/SRC
lcd /bin/DST
mget *.*
bye

Please always use code tags when posting any code fragments or data samples. If you are not sure how to use code tags, then please have a look at this forum video tutorial

Try this:-

ftp -i -n << EOF
open 172.17.1.1
user login password
prompt off
cd /opt/SRC
lcd /bin/DST
mget *.*
EOF

You need to tell it what to do. What you have is a script that will start FTP and then wait until it ends before carrying on and trying to execute the next line, i.e. quote user login password

To get this to be seen as input to the ftp command, you will need to wrap it up a little:-

#!/bin/bash
ftp -inv 172.17.1.1  <<-EOFTP
quote user login password
bin
prompt off
cd /opt/SRC
lcd /bin/DST
mget *.*
bye 
EOFTP

The EOFTP label at the end marks where the input stops. Mind you, I'm writing this as a ksh writer with very limited bash experience at the moment, so this may not work, but give it a go.

If you indent your code to make it more readable, the EOFTP at the end cannot be space indented or it will be ignored. Use the Tab key instead.

I hope that this helps.

Robin
Liverpool/Blackburn
UK

thanks guys! apologies again, but i'm new to this.

steve.

We were all new to it once too :stuck_out_tongue: - and it's nice to have someone display pleasure :slight_smile: rather than the usual blank we probably all get at work. Thanks for that :wink:
Did it do the trick?

Robin
Liverpool/Blackburn
UK