Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-09-16
5
Medium Priority
?
333 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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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…
Suggested Courses

722 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