Upload latest file to ftp

Hi,

I want to create a script that parses the content of a file (on each line there is a filename with full path containing the latest fiels created on that day) and uploads every file to a ftp location.
Any elegant way to do it ?

Dear liviusbr,

I have a few to questions pose in response first:-

  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

Kind regards,
Robin

Hi,

This is what I have tried :

LOCALBASE=/data/backups
SERVER=10.2.37.70
USER=test
PASSWD=test
INPUT=/data/backups/today.txt
FILETYPE=binary

## ftp put doesn't create directories by itself so
## we check for missing remote dirs, and create them

## upload the files
for ITEM in $(cat $INPUT); do
        FILE=$(basename $ITEM)
        ## ftp starts here
        ftp -v -n $SERVER <<END_OF_SESSION
        user $USER $PASSW
        $FILETYPE
        lcd $LOCALDIR
        cd $REMOTEDIR
        put $FILE
        bye
END_OF_SESSION
done

Thanks for the code.

Assuming that this isn't working for you (you don't say where) I can see an issues to consider - the lcd refers to a variable that you don't declare.

Are there other errors/symptoms that I can't spot so easily? Perhaps you can share some sample content of the $INPUT file, wrapped in CODE tags.

Robin

#!/bin/bash

wput -qq /source/path/of file/to upload/xyz.txt ftp://ftp_user:ftp_pass@host/path/to/remote/directory/

P.S. Use wput -u if you want to update an existing file -q (or qq ) if you don't want to see no messages during execution of the script