Bash FTP Script

Hello, I have a bash script used to telnet and transfer files which works great. Trying to FTP to a box that does not support telnet. Been told to use ssh to the user@someIPaddress. I can log in manually but can't seem to make this script work. And help would be appreciated.

#!/bin/bash
HOST=ssh user@x.x.x.x
USER=user    
PASSWD=passwd
cd /home/
chmod 700 *
list_file=` file`


ftp -nv <<-!x
open $HOST
user $USER $PASSWD
cd /home/somedir
binary
put $list_file
bye
!x
exit 0

Did you try....

scp file user@x.x.x.x:

Transfer your key to do this without specifying a password

It did not work.

#!/bin/bash
HOST=scp file user@x.x.x.x
USER=user    
#PASSWD=passwd
cd /home/somedir
list_file=` file`


ftp -nv <<-!x
open $HOST
user $USER $PASSWD
cd  /somedir/
binary
put $list_file
bye
!x
exit 0

Here is the error message

 cannot open: No such file or directory

The scp should replace your entire ftp command.

What's the contents of list_file ?

the contents of

list_file=` .csv`

is a .csv file

Are you sure THAT file exists on the server?

this doesn't make much sense...
If you want to use ftp and transfer all .csv files instead of 'put':

 mput *.csv

if the objective is somewhat different, you need to explain it a bit further, but this 'list_file' assignment doesn't make much sense...

The script is not getting past the login negotiations part.

220 xxxx FTP server ready.
331 Password required for xxxx.
530 Login incorrect.
Login failed.
530 Please login with USER and PASS.
530 Please login with USER and PASS.
(local-file) (remote-file) 221 Goodbye.

I can manually login so I know the username and password are good. Strange one.

---------- Post updated at 05:35 PM ---------- Previous update was at 05:31 PM ----------

This part of the script puts the file

put $list_file

Here is the whole script though

#!/bin/bash
HOST=scp file user@x.x.x.x
USER=user    
#PASSWD=passwd
cd /home/somedir
list_file=` .csv`


ftp -nv <<-!x
open $HOST
user $USER $PASSWD
cd  /somedir/
binary
put $list_file
bye
!x
exit 0

I repeat: "scp ..." is not the host!

They are telling you to use SCP instead of FTP.

Your entire script would be

scp *.csv user@x.x.x.x

Ok, I only did what was suggested. So I am back to where I started then before opening this thread.

So your HOST variable is scp file user@x.x.x.x which after the assignment is done sets HOST to scp .
Your PASSWRD is commented out: #PASSWD=passwd .
I think there're a couple (at least) things that needs to be fixed first.

Not quite. People have suggested you try this code:

scp *.csv user@x.x.x.x

If you have ssh, you also have scp. Have you tried it yet? Does it work for you? If not, in what way does it not work for you?

ftp -nv <<-!x
open $HOST
user $USER $PASSWD
cd /home/somedir
binary
put $list_file
bye
!x

This is your man ftp ("linux") command. The red line tries to open an FTP connection to $HOST. Regardless of what you put in there, it's going to try and use FTP protocol (and in this case will fail since what you have is not a valid host name). You can't just put scp or ssh in there to use SSH.

To do that you need a different command, such as man scp ("linux") or man sftp ("linux").

What people are suggesting is that you replace all of your ftp command with the scp command. So, your example script would look like:

#!/bin/bash
HOST=x.x.x.x
USER=user

cd /home/somedir

scp *.csv ${USER}@${HOST}

exit 0

Ok I've never used scp but have tried a few things. Getting prompted for a password though.

 scp user@host1 /home/dir/test.csv user@host2:/dir

As blackrageous said earlier, for passwordless transfer you need to set up SSH keys.

Leave the 'user@host1' out if you are copying local files onto host2. It will try to copy a file named 'user@host1' and complain that such a file does not exist.

Thank you Corona, that was it!