Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP from a list using mls command

Status
Not open for further replies.

dsm666

IS-IT--Management
Mar 9, 2004
40
US
I ran into a script that does exactly what I am looking for; except the last part which recalls the todo.lst. My question is how do I recall the todo.lst to actually start the transfer. Everything works up until the quit command below. here is the code and Thank you

#!/bin/sh
clear
# change local directory
cd [local-directory]

#collect file names
ftp -ni ftp.abccompany.com <<EOF
user [user] [password]
cd /OUT
mls W945*.* list.txt
quit
EOF

# create ftp action list
echo >>todo.lst user [user] [password]
while read N
do
echo >>todo.lst cd /OUT
echo >>todo.lst get $N
echo >>todo.lst rename $N ARCHIVE/$N
done <list.txt

echo >>todo.lst quit

# ftp transfer process
ftp -nv ftp.abccompany.com <todo.lst

# cleanup
rm todo.lst
 
Can you post the actual code you are trying? This won't work as you posted it because it has things you need to replace such as "[local-directory]", "[user]", and "[password]".

Also, the "[tt]echo[/tt]" commands are all wrong.

I didn't test it, but this might get you closer...
Code:
#!/bin/sh

LOCAL_DIR=<put local working directory here>
USER=<put FTP username here>
PASSWD=<put FTP password here>

# change local directory
cd ${LOCAL_DIR}

#collect file names
ftp -ni ftp.abccompany.com <<EOF
user ${USER} ${PASSWD}
cd /OUT
mls W945*.* list.txt
bye
EOF

# create ftp action list
echo "user ${USER} ${PASSWD}" > todo.lst 
echo "cd /OUT" >> todo.lst

while read N
do
    echo "get ${N}" >> todo.lst
    echo "rename ${N} ARCHIVE/${N}" >> todo.lst 
done < list.txt

echo "bye" >> todo.lst

# ftp transfer process
ftp -nv ftp.abccompany.com < todo.lst

# cleanup
rm todo.lst list.txt
I also moved your variable definitions for local-dir, user, and password to the top, so you only have to change them in one place.

 
Thanks so much for doing that.
the part that doesn't work is the last part
ftp -nv ftp.abccompany.com < todo.lst

for some reason ftp can't handle < todo.lst

Here is the code:
#!/bin/ksh

set -x

exec >> $HOME/log/import_log.log 2>&1

STARTTIME=`date +"%D-%T"`
echo $STARTTIME - Begin

cd $HOME/temp
# local directory
LOCAL_DIR=/ceunix_test/ceunix/temp/winftp_log/ftp004

FTP_HOST='pfgdsmftp004'
FTP_USER='tdftptst'
FTP_PASSWD='XXXXXXX'
REMOTE_DIR="test10"

ftp -nv $FTP_HOST <<EOF
quote USER $FTP_USER
quote PASS $FTP_PASSWD
cd $REMOTE_DIR
mls * $HOME/temp/list.txt
bye
EOF

todolst="$HOME/temp/todo.lst"
# create ftp action list
echo >>$todolst user [tdftpts] [XXXXXX]
while read N
do
echo >>$todolst cd /test10
echo >>$todolst get $N
echo >>$todolst delete $N
done <$HOME/temp/list.txt

echo >>$todolst quit

# ftp transfer process
ftp -nv $FTP_HOST < $todo.lst

# cleanup
rm $todo.lst

here is the log file output:


+ + date +%D-%T
STARTTIME=02/16/10-14:11:38
+ echo 02/16/10-14:11:38 - Begin
02/16/10-14:11:38 - Begin
+ cd /ceunix_test/ceunix/temp
+ LOCAL_DIR=/ceunix_test/ceunix/temp/winftp_log/ftp004
+ FTP_HOST=pfgdsmftp004
+ FTP_USER=tdftptst
+ FTP_PASSWD=XXXXXX
+ REMOTE_DIR=test10
+ ftp -nv pfgdsmftp004
+ 0<<
quote USER tdftptst
quote PASS XXXXXXX
cd test10
mls * /ceunix_test/ceunix/temp/list.txt
bye
Connected to pfgdsmftp004
220 Microsoft FTP Service
331 Password required for tdftptst.
230 User tdftptst logged in.
250 CWD command successful.
output to local-file: /ceunix_test/ceunix/temp/list.txt? 200 PORT command successful.
150 Opening ASCII mode data connection for file list.
226 Transfer complete.
local: /ceunix_test/ceunix/temp/list.txt remote: *
149 bytes received in 0.0043 seconds (33.45 Kbytes/s)
221
+ todolst=/ceunix_test/ceunix/temp/todo.lst
+ echo user [tdftpts] [XXXXXXX]
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ 0< /ceunix_test/ceunix/temp/list.txt
+ read N
+ echo cd /test10
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ echo get 39004494_PRINCIPAL_20100211_Energy-Util-Basic_Team_Mkt_Structure.csv
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ echo delete 39004494_PRINCIPAL_20100211_Energy-Util-Basic_Team_Mkt_Structure.csv
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ read N
+ echo cd /test10
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ echo get 39005000_PRINCIPAL_20100211_PGI_Asset_Report_Agg_Europe_Region.csv
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ echo delete 39005000_PRINCIPAL_20100211_PGI_Asset_Report_Agg_Europe_Region.csv
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ read N
+ echo cd /test10
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ echo get test1.pdf
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ echo delete test1.pdf
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ read N
+ echo quit
+ 1>> /ceunix_test/ceunix/temp/todo.lst
+ ftp -nv pfgdsmftp004
+ etc/importfile.sh[40]: .lst: cannot open
+ rm .lst
.lst: No such file or directory

 
here is the output after the changes your suggested:

02/16/10-14:43:48 - Begin
Connected to pfgdsmftp004.principalusa.corp.principal.com.
220 Microsoft FTP Service
331 Password required for tdftptst.
230 User tdftptst logged in.
250 CWD command successful.
200 PORT command successful.
150 Opening ASCII mode data connection for test1.pdf(162 bytes).
226 Transfer complete.
local: test1.pdf remote: test1.pdf
162 bytes received in 0.0046 seconds (34.19 Kbytes/s)
350 File exists, ready for destination name
550 /ceunix_test/ceunix/temp/test1.pdf: Access is denied.
221
 
I guess you figured out that this line:

Code:
ftp -nv $FTP_HOST < $todo.lst

Should be:

Code:
ftp -nv $FTP_HOST < $todolst

Regarding the "access denied" message, have you created the /ceunix_test/ceunix/temp destination directory on the remote server?

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top