User412387
User412387

Reputation: 89

FTP files in different folders using shell script

I'm trying for an ftp script, that sends files in different folders within the same connection, but no luck with below script.

#!/bin/bash
HOST_NAME=host.server
username= user_name
passwd=   password
remote = /path_to_remote/folder
local =  /path_to_local/folder
folder=$1
pwd
ftp -in <<EOF
open $HOST_NAME
user $username $passwd
cd local/ 
lcd remote/ 
put a_filename_<timestamp>.txt 
mkdir $remote/$folder
cd $remote/$folder
lcd $local/$folder 
put b_filename.txt 
close 
bye

Adding to this, at run-time, is it possible to send only the latest files created in the last 10 minutes?

Upvotes: 0

Views: 1203

Answers (1)

agc
agc

Reputation: 8406

Try this:

#!/bin/bash
HOST_NAME=host.server
username=user_name
passwd=password
remote=/path_to_remote/folder
local=/path_to_local/folder
folder="$1"
pwd
ftp -in <<EOF
open "$HOST_NAME"
user "$username" "$passwd"
cd local/ 
lcd remote/ 
put a_filename_<timestamp>.txt 
mkdir "$remote/$folder"
cd "$remote/$folder"
lcd "$local/$folder" 
put b_filename.txt 
close 
bye
EOF

Notes:

  1. The shell doesn't allow spaces next to =.

  2. Quote variables.

  3. OP code lacked closing EOF.

I've left the <timestamp> alone, that'd be a different Q.

Upvotes: 1

Related Questions