Solved

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

Posted on 2014-09-16
5
305 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
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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