Solved

List files on a FTP or SFTP server and get only the files in the list

Posted on 2014-09-16
5
310 Views
Last Modified: 2014-10-06
I have some FTP and SFTP scripts that do a mget to pull files, however need to list files on the FTP/SFTP server and only pull those files in the list or certain files in the list?

Any examples would be helpful.

Thanks.
0
Comment
Question by:bje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40328070
Try something like:
ftp -n -v $REMOTSERVER << eof > FileList.txt
user $FTPUSR $FTPPASSWD
cd $FTPDIR
dir MyFiles*
eof
#---- Now you have the names in "FileList.txt"
# 

Open in new window

0
 
LVL 62

Expert Comment

by:gheist
ID: 40328271
You can just oportunistically fetch files with wildcards you need..
0
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 500 total points
ID: 40328431
You first get the list the way MikeOM_DBA is suggesting. Then modify that (local) file that contains your 'wanted' files and create an FTP script that is getting each wanted file. Let's call that file modified_filelist.txt

Are you working on a Linux machine to get the files? Then you can easily create the 'get' script like this:

echo "ftp -n -v $REMOTESERVER << eof" > ftpscript
echo "user $FTPUSR $FTPPASSWD" >> ftpscripts
echo "cd $FTPDIR" >> ftpscript
cat modified_filelist.txt | while read line
do
echo "get $line" >> ftpscript
done;
echo "bye" >> ftpscript
echo "eof" >> ftpscript

Open in new window


Then run that ftpscript:

sh ./ftpscript
0
 

Author Comment

by:bje
ID: 40357672
Thanks for all the solutions
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question