-1

I need help regarding downloading the files from FTP Server to the Local Server.

for downloading i need to use the FTP In batch Mode capability and I have a txt file with with all the files which needs to be downloaded.

file.txt

cap/media/101/101.mp4
cap/media/102/102.mp4
cap/media/103/103.mp4
cap/media/104/104.mp4
cap/media/105/105.mp4
cap/media/106/106.mp4 

cap/media/101 is the folder structure inside the FTP user root and 101.mp4 is the file.

so the folder structure for 1000 of file is same and the mp4 is located as listed.

so i need a bash script which can run in Batch mode capability and download all the files automatically to the local Storage.

I have created that script but it is not working, hopefully someone can give me some hints,

###########################
HOST="ftp.remote.com"
USER="media"
PASSWORD="test"
FILE="/tmp/list.txt"
###########################



 cd /tmp/
while read p; do 
pt=$(dirname $p);
h="/"
pth=$pt$h
mxf=$(basename $p);
#echo $pth;
#echo $mxf; 
ftp -n -v >> /tmp/filetransfer.log 2>&1 $HOST <<EOF
binary
user $USER $PASSWORD
prompt
lcd /tmp/media
cd $pth
mget $mxf
quit
EOF
done < /tmp/list.txt

and that is the output of the FTP Can you please help me here , I am not understanding what excatly i am doing wrong.

Connected to ftp.remote.com
220-FTPD
220 This is a private system - No anonymous login
200 TYPE is now 8-bit binary
331 User media OK. Password required
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
Interactive mode off.
Local directory now /tmp/media
250 OK. Current directory is cap/media
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.

I am having this error: 221-Goodbye. You uploaded 0 and downloaded 0 kbytes.

thank you for any comment and advice in Advance.

17
  • Can you share the error, that you see?
    – Nisheet
    Feb 8, 2017 at 13:34
  • Connected to ftp.remote.com. 220-FTPD 220 This is a private system - No anonymous login 200 TYPE is now ASCII 331 User media OK. Password required 230 OK. Current restricted directory is / Remote system type is UNIX. Using binary mode to transfer files. Interactive mode off. 221-Goodbye. You uploaded 0 and downloaded 0 kbytes. 221 Logout this is the Output, so now files are being downloading.
    – kunal
    Feb 8, 2017 at 13:35
  • So its downloading now?
    – Nisheet
    Feb 8, 2017 at 13:37
  • @nisheet , it didnt download, as you see the upload and download is 0 kbyets
    – kunal
    Feb 8, 2017 at 13:38
  • Instead of passing file names does mget * work?
    – Nisheet
    Feb 8, 2017 at 13:45

2 Answers 2

0

Follow upto the comments this should probably work:

HOST="ftp.remote.com"
USER="media"
PASSWORD="test"
FILE=`cat /tmp/list.txt`
cd /tmp/localstorage

ftp -n -v >> /tmp/ftptransfer.log 2>&1 $HOST <<END_SCRIPT
ascii
user $USER $PASSWORD
prompt
mget $FILE
quit
END_SCRIPT
0

I wrote the following script to avoid errors with filenames which contains a space:

#!/bin/bash

host=ftp://ftp.local
username=user
password=pw
cmd="curl -O -u ${username}:${password} ${host}/"
cd public_html
cat ~/list.txt | while read files ; do $cmd"${files}" | echo ${files};
done | tee -a ~/ftp.log

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .