Scripting with FTP Process

Hi Guys,

Good day ULF! I have a general "auto-ftp" code which looks something like this:

#!/bin/sh

cd $1
ftp -v -n $2 << EOF
user $3 $4
prompt
cd $5
bin
mput $6
quit
EOF

This works pretty well, but I'm thinking of how can I make a code by maybe including on this code, for example checking or comparing the filesize that has been transferred from the one that has been received on a particular remote server, and if so happen that the received file has a size of 0 bytes, it will retry and send the file until the received file is exactly same size with the transferred file.

Say for example (mput $6) then $6 has a size of 1000 bytes, then I want that when the received file was 0 bytes, I want the code to retry it.

Is this possible? Yah I know that it's pretty much to include ls -lrt, then after execution by manually checking it, but the process will be put in CRON so that it will be somewhat automated.

Please advise!

BR,
rymnd_12345

Please mention the Operating System and version of both computers concerned and something about the type of file being transferred.
Do you have remote Shell and interactive Shell access to both computers?

Hi methyl,

  • Both servers are working on a Linux OS.
    -Type of file is a created file (run by another script) under the source server. Maybe some kind of file containing a list of lines only.
  • Yes, remote and interactive shell are both present on both servers.

BR,
rymnd_12345

Any reason you are using ftp rather (than say scp or rcp ) ?

Hi methyl,

Haven't tried yet before, but I've tried to use this command below:

scp FILE user@<IP>:/home/output/

then of course it prompted for a password, followed by successful secure copy of file to the other server.

Password:
FILE                                                                                                                           100% 1456     1.4KB/s   00:00

Problem here I think is that on the automation part since I want to put it on CRON, and this will require an expect scripting (guess so?).

Please advise on how can I improve my code like I want to make sure that the file has been transferred/copied to the other server automatically.

BR,
rymnd_12345

Here is a pretty good worked example of setting up scp without password:

[Pass on Passwords with scp | Linux Journal](http://www.linuxjournal.com/article/8600)