FTP failed to copy mulitple files from multiple directory

I am using below scripts to copy all the files from multiple folders. By executing individually command i am able to copy all the files but using scripts only getting first file. System is ignoring the second CD and mget command.

HOST=server.com
USER=loginid
PASSWD="abc"
echo "open $HOST
user $USER "${PASSWD}"
binary
prompt off" > /tmp/ftp.$$

echo "cd /home/mylogin/Test"  >> /tmp/ftp.$$
echo "mget *.* "  >> /tmp/ftp.$$
echo "cd \"/home/mylogin/Test2/Important Doc/\" " >> /tmp/ftp.$$
echo "mget *.*  "  >>  /tmp/ftp.$$
echo "bye" /tmp/ftp.$$
ftp -ivn < /tmp/ftp.$$

Similarly I want to add around 50 folders to copy all the files from windows folder to unix folder. Please advice.

You don't have to reopen the same file 50 times to add 50 lines. You may not even need a file at all.

That 'bye' doesn't even end up in the file at all.

"*.*" is a DOS-ism, if you want all files in UNIX use *

ftp <<EOF
open $HOST
user $USER "${PASSWD}"
binary
prompt off
cd /home/mylogin/Test
mget *
cd "/home/mylogin/Test2/Important Doc/"
mget *
bye
EOF

Still not working.

I tried another method - creating a file and passing to FTHub jobs.

/usr/bin/ftp -ivn < /tmp/ftp.24459 

where /tmp/ftp/24459 is as below

open server.com
user loginid Passwrod 
binary
prompt off
cd /home/mylogin/Test
mget *
cd /home/mylogin/Test2/Important_Doc/
mget *
bye
.

Still files from first folder are being copied. I swaped the folder then same file are coping from first folder only.

Similarly i want o add 50 files -

cd /home/mylogin/Test
mget *
....
....
cd /home/mylogin/Test2/Important_Doc/
mget *

:confused:

---------- Post updated at 04:40 PM ---------- Previous update was at 02:49 PM ----------

Also noticed, that if there is no file present then files copied from second folder.
Otherewise scripts perform the copy from first folder only.

:wall:

Try starting with

cd /home/mylogin/Test2/Important_Doc/
mget *

instead. It may be that it doesn't have permissions to access one of these folders and fails.

I tested individually folder by manually FTP. It's working.
Even I changed the sequence i.e. Scripts copy files for first folder - /home/mylogin/Test2/Important_Doc/. It ignores the second.

cd /home/mylogin/Test2/Important_Doc/
mget *
cd /home/mylogin/Test
mget *

:frowning:

Why not just create two scripts, one for each directory, and login twice.
Also consider using a .netrc file so that the userid and password are not stored in the script.

It's working after applying the 'pwd' just after mget *

cd /home/mylogin/Test2/Important_Doc/
mget *
pwd
cd /home/mylogin/Test
mget *

Thanks a lot
:slight_smile: