Solved

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

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

Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

623 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