Solved

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

Posted on 2014-09-16
5
291 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
Comment Utility
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 61

Expert Comment

by:gheist
Comment Utility
You can just oportunistically fetch files with wildcards you need..
0
 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 500 total points
Comment Utility
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
Comment Utility
Thanks for all the solutions
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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.
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now