Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


can you ftp only a set number of files?

Posted on 2006-11-12
Medium Priority
Last Modified: 2013-11-29
i have a location that will have lots of files in at any one time (all csv files), but i only want to ftp approx 10 files at a time (being the 10 oldest files), using a wildcard as the filenames will always be different. Does anyone know if this is possible and if so...how.
Question by:Aidy_B
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
  • 4
  • 4
  • 2
  • +1

Expert Comment

ID: 17926988
If you use a GUI FTP client, you should be able to highlight the 10 files you want to transfer and click transfer.  IE is a GUI FTP client, or you can get wsftp.  At the command line use mput and mget to transfer multiple files.  If the file names you are wanting to transfer are in some sort of sequence you can use a wildcard.

Basic Example:

file names are


You could get 001 through 009 with:

ftp:> mget extract..00*

Expert Comment

ID: 17926991
Ignore that last "extract001.csv".  It was off my screen when I clicked submit.

Expert Comment

ID: 17928174
if the names are not named as drawlin suggested, then there is no way to do just 10 files. You can write a small shell script (if linux) or a small C program that can do this quite easily.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Expert Comment

by:Nilesh Roy
ID: 17929276
u can create a batch file (.bat file)

in that in the ftp, you can use the commang mget *XXX*.csv to donaload multiple files.

in windows you can then schedule this batch file to be executed at specific intervals.

Need more clarifications?



Author Comment

ID: 17934087
Apologies to everyone for the lack of detail. i was in a bit of a hurry and just wanted to get the ball rolling, if you know what i mean. Here goes for an indepth explanation:

csv files are produced on a remote server with random numbered filenames (random to all intense purposes anyway) being approx 8 characters long. these files are then required by a different system but need to be processed by that system in the date/time order that they were produced. this different system is fed the files by a scheduled FTP operation which supplies them to a pc/plc setup. this pc/plc setup modifies the files by cutting some of the data out of them then combines all the files in to a single text file before being called via another ftp operation into the plc. as the plc then uses the files to populate a finite number of data blocks, it is imperative that the number of csv files that were used to create the txt file is not so large that the plc runs out of data blocks to populate, and then bring the whole system into a crash and burn situation.

I have managed to create a setup that will ftp to the pc, modify the files, combine them, and put the finished txt file in the correct loction for the plc, with the added safety that it will not repeat this operation untill it has detected that the previous txt file no longer exists (which is controlled by the plc deleting the file upon successfully loading it), but the bit i am trying to ahieve is limiting each ftp operation (and hence each txt file) to only 10 or so of the original files so that the plc can be told only to ftp a new file in if it has at least 10 datablocks free to populate. but to add to the problem, these will need to be the next 10 in the sequence of the time they were created.

The system creating the files is beyond my control and if for any reason the process which the plc runs was to stop or slow down, then the amount of files available to ftp the next time the plc is ready to upload could be quite large as the files will be produced regardless of the proccesses curent status.

another way that is acceptable is if the limit of 10 files can be achieved on the pc by only transfering that many out of the main folder receiving the ftp files, into a different folder which can then be used to feed the conversion process, but once again it would need to be in the order of date creation.

as an end note, none of the csv files that are produced in the first place to ftp have filnames that would be known as they are just a build code that is produced (so basically the filenames mean nothing to anyone else other than the system itself).

if anyone has managed to read down as far as this....well done, and thank you for just that effort alone, yet alone if anyone actually has a solution.

thanks in advance,

Expert Comment

ID: 17934425
   again there is no command you can execute to make this happen. However a small script can do this quite easily.
The solution would be
1. ls -altr will sort files by creation date. Earliest to latest
2. awk can then strip out just the files name

ls -altr | awk '{ print($9) }'

Now you have all the files listed by creation date.
Next you take the top 10 files and feed delete it from the original folder and place it onto a new one

I guess the other end will just pick up all files from new folder.

I can write a small bash script that can do this for you. it is fairly simple.

Author Comment

ID: 17934562
hi periferral,
i am interested in this solution but where you mention taking the top ten files into another folder, is this done by script? i ask as the whole process is ran unattended 24/7 and needs to be able to operate with no human intervention.

thanks again, aidy.

Accepted Solution

periferral earned 2000 total points
ID: 17934671
aidy.. this is what the script would look like. The shell needs to be csh or tcsh.
The 1st line will list 10 file names and copy them to a new directory called avitest. In you case this probably needs to be a move (mv) rather than a copy. You can also remove the echo since you dont need to see which files were moved. Create a file called test.sh and copy the files below

set lstfiles=`ls -altr | awk '{ print($9) }' | grep . | sed 10q | tr "\n" " "`
foreach file ($lstfiles)
   echo $file
   cp $file ./avitest/

once this is done. chmod +x test.sh and run the script and you should see the files copied to the new location.

For this to be done automatically you can run this script as frequently as you need from a cron job.


Author Comment

ID: 17934869
i am not sure that it will be permissible for me to run this on the server but i will find out in the morning. if not, is there any way of doing it on the local pc after i have pulled the files off the server? (the local machine being win xp os)
cheers, aidy

Expert Comment

ID: 17935013
aidy.. you can to do the same thing from the local machine. However, this is not be as simple as executing on the remote server. I mean, you will need a shell script like tcl or perl maybe that can do something similar. the problem is that you need to ftp to the server, get the directory listing and then get only 10 files at a time and process them and return. using the ftp client and processing the information is harder since FTP does not have all the commands that are in a basic linux machine to do such processing so you will need to code in that logic.


Author Comment

ID: 18057039
hello again.

apologies for the delay. this problem is twisting and turning a bit but the solutions offered have given the neccesary food for thought for now. i am going to close the question and sort out the finer details at a later date when the project is also being finalised. thanks for all the input. points are going to periferral as the solutions given are of the most use at this time.


Featured Post

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

636 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