FTP mget * not working after change directory -cd

Hi everyone,

I have an Linux FTP script to get files from different AS400 mailboxes and store in different local directories.
I had to use mget * option becuase there is no fixed destination file name means filename can change.
The following FTP script is working fine if we have single file per mailbox (for ex:- "N0001" file in "TE.TZ.MBOX.XMIT.FPFD" mailbox) .
But if we have multiple files in mailboxes (for ex:- N0001,N0002 in"TE.TZ.MBOX.XMIT.FPFD" mailbox) the following script is not working correctly.

For example :-

if there are these two files in TE.TZ.MBOX.XMIT.FPFD mailbox
N0001
N0002

if there are these two files in TE.TZ.MBOX.XMIT.FPGD mailbox
N0003
N0004

after running the following script, Local dir "/ford/thishost/proj/batch/sonic/server/data/de/fpf" is having N0001 and N0002(good) but local dir "/ford/thishost/proj/batch/sonic/server/data/de/fpg" is still having N0001 and N0002(bad) but its not right as I am expecting N0003 and N0004.

somehow when there are multiple files in each mailbox change directory (cd) command is not working.

Could you please let me know if you have any idea how to fix this issue,

Many thanks in advance.

FTP script is :-

ftp -n <<_LABEL
open ftp.sun.com
user $USERID $PSSWRD
has
cd 'TE.TZ.MBOX.XMIT.FPFD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/fpf
mget *
has
cd 'TE.TZ.MBOX.XMIT.FPGD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/fpg
mget *
has
cd 'TE.TZ.MBOX.XMIT.FPAD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/fpa
mget *
has
cd 'TE.TZ.MBOX.XMIT.ASVD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/asv
mget *
has
cd 'TE.TZ.MBOX.XMIT.RVGD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/rvg
mget *
has
cd 'TE.TZ.MBOX.XMIT.FPVD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/fpv
mget *
has
cd 'TE.TZ.MBOX.XMIT.ASGD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/asg
mget *
has
cd 'TE.TZ.MBOX.XMIT.AFGD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/afg
mget *
has
cd 'TE.TZ.MBOX.XMIT.ASFD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/asf
mget *
has
cd 'TE.TZ.MBOX.XMIT.FPPD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/fpp
mget *
has
cd 'TE.TZ.MBOX.XMIT.VMGD'
lcd /ford/thishost/proj/batch/sonic/server/data/de/vmg
mget *
close
bye

Is 'has' 'hash', and why toggle it so often?

When you cd, you are asking for a subdirectory unless you cd /topdir.

The script is working fine if we have single file in one mailbox (ie one directory) , if we have only mutliple files in the mailbox then only the problem. any ideas please.

Does it work if you have a session per directory?

Still seems like you need to cd to ../'TE.TZ.MBOX.XMIT.FPGD'

Let me rephrase what DGpickett's saying.

When you do cd 'TE.TZ.MBOX.XMIT.FPFD' your current directory changes from /current/path/ to /current/path/TE.TZ.MBOX.XMIT.FPFD/. You download those files and it goes fine.

Next you do cd 'TE.TZ.MBOX.XMIT.FPGD' which tries to change the dir from /current/path/TE.TZ.MBOX.XMIT.FPFD/ into /current/path/TE.TZ.MBOX.XMIT.FPFD/TE.TZ.MBOX.XMIT.FPGD which of course doesn't exist.

You have to cd '../TE.TZ.MBOX.XMIT.FPGD' to tell it to go up one dir.

for ftp scripting I have always found lftp to be easier and better. Take a look at it as it looks like it has what you need.

1 Like