Solved

can you ftp only a set number of files?

Posted on 2006-11-12
11
363 Views
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.
cheers,
aidy.
0
Comment
Question by:Aidy_B
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 5

Expert Comment

by:drawlin
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

extract001.csv
extract002.csv
extract003.csv
extract004.csv
extract005.csv
extract006.csv
extract007.csv
extract008.csv
extract009.csv
extract010.csv
extract011.csv

You could get 001 through 009 with:

ftp:> mget extract..00*
extract001.csv
0
 
LVL 5

Expert Comment

by:drawlin
ID: 17926991
Ignore that last "extract001.csv".  It was off my screen when I clicked submit.
0
 
LVL 4

Expert Comment

by:periferral
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.
0
 
LVL 4

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?

Regards,

Nilesh.
0
 

Author Comment

by:Aidy_B
ID: 17934087
Hi.
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,
aidy.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:periferral
ID: 17934425
aidy
   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.
0
 

Author Comment

by:Aidy_B
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.
0
 
LVL 4

Accepted Solution

by:
periferral earned 500 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

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

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.

0
 

Author Comment

by:Aidy_B
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
0
 
LVL 4

Expert Comment

by:periferral
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.




0
 

Author Comment

by:Aidy_B
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.

Aidy.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Data center, now-a-days, is referred as the home of all the advanced technologies. In-fact, most of the businesses are now establishing their entire organizational structure around the IT capabilities.
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

13 Experts available now in Live!

Get 1:1 Help Now