# Need help in FTP script to archive

**URL:** <https://community.unix.com/t/need-help-in-ftp-script-to-archive/367029>\
**Category:** Shell Programming and Scripting\
**Created:** [June 14, 2017, 7:48am UTC](https://community.unix.com/t/need-help-in-ftp-script-to-archive/367029 "2017-06-14T07:48:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spidy](https://community.unix.com/letter_avatar/spidy/32/6_449c533f586939b6e5f246632a46421f.png) [@spidy](https://community.unix.com/u/spidy)\
**Post date:** [June 14, 2017, 7:48am UTC](https://community.unix.com/t/need-help-in-ftp-script-to-archive/367029/1 "2017-06-14T07:48:33Z")

</div>

Hi Guys,

I am unable to archive the FTP files from FTP source path to FTP archive path.Currently i am running this script from the Local server. Can someone help me here.  
Code:

```nohighlight
#!/bin/ksh
set -x
HOST='xxxx'
USER='xxxx'
PASSWD='xxxx'
PORTNO='9999'

FILE_NAME=$1
FTP_SRC_PATH=$2
FTP_ARC_PATH=$3
CURR_PATH=`pwd`
#CURR_PATH='/Product/Asset/Source'

ftp -n $HOST $PORTNO <<ENDfilelst
cd $FTP_SRC_PATH
quote USER $USER
quote PASS $PASSWD
bin
prompt
lcd $CURR_PATH
cd $FTP_SRC_PATH
ls $FILE_NAME archivefilelist.txt
quit
ENDfilelst
cat archivefilelist.txt
cat archivefilelist.txt | rev | cut -d' ' -f1 | rev > tempfile
mv tempfile archivefilelist.txt

while read line
do
ftp -n $HOST $PORTNO <<ENDfilelst
quote USER $USER
quote PASS $PASSWD
bin
prompt
lcd $CURR_PATH
rename $FTP_SRC_PATH/$line $FTP_ARC_PATH/$line
quit
ENDfilelst
done < archivefilelist.txt

```

I am getting below error

```nohighlight
+ ftp -n wmx-mft-test.avnet.com 8121
Command not recognized or allowed.
Interactive mode off.
Local directory now /var/local/ei/etl/Scripts
+ cat archivefilelist.txt
+ cat archivefilelist.txt
+ rev
+ cut '-d ' -f1
+ rev
+ mv tempfile archivefilelist.txt
+ read line
+ rm archivefilelist.txt

```

---

<div class="post-metadata">

**Author:** ![rdrtx1](https://community.unix.com/user_avatar/community.unix.com/rdrtx1/32/2721_2.png) [@rdrtx1](https://community.unix.com/u/rdrtx1)\
**Post date:** [June 14, 2017, 9:59am UTC](https://community.unix.com/t/need-help-in-ftp-script-to-archive/367029/2 "2017-06-14T09:59:16Z")

</div>

Try moving the `cd $FTP_SRC_PATH` line after the `quote` lines in the `ftp` script.

---

<div class="post-metadata">

**Author:** ![spidy](https://community.unix.com/letter_avatar/spidy/32/6_449c533f586939b6e5f246632a46421f.png) [@spidy](https://community.unix.com/u/spidy)\
**Post date:** [June 14, 2017, 2:28pm UTC](https://community.unix.com/t/need-help-in-ftp-script-to-archive/367029/3 "2017-06-14T14:28:18Z")

</div>

Try moving the cd $FTP\_SRC\_PATH line after the  
quote lines in the ftp script.

I am still facing the same error.Can someone help me here

Output Error:

```nohighlight
+ FTP_SRC_PATH=/Product/Asset/Source
+ FTP_ARC_PATH=/Product/Archive
++ pwd
+ CURR_PATH=/var/local/ei/etl/Scripts
+ ftp -n wmx-mft-test.avnet.com 8121
?Invalid command
Interactive mode off.
Local directory now /var/local/ei/etl/Scripts
+ cat archivefilelist.txt
+ cat archivefilelist.txt
+ rev
+ cut '-d ' -f1
+ rev
+ mv tempfile archivefilelist.txt
+ read line
+ rm archivefilelist.txt

```
