Is there a way to loop through the files in an FTP from MS DOS.? Thanks.
The technique I'm using is to have two FTP scripts. One I use to capture the output of a DIR command. Having captured the DIR, I parse that for the names of files to be downloaded. Then I use the second script with information from the first to download the files.
Related
I am using mget to retrieve files from a remote server to local directory in Windows.
lcd C:\E920_1\autopkg\saveE1logafterDir\serverlog
mget /slot/ems2576/appmgr/jdedwards/e920/6210/log/jde_*.log
Now, I wish to add additional step to retrieve out of this list, only the files which contains the word "PACKAGE BUILD" inside it.
How do I accomplish it?
It's not possible. FTP protocol does not have an API to find files by their contents.
See also Search Within Files On Remote FTP Site.
So any implementation you will use will have to download all log files and search their contents locally.
In a batch file, you can use findstr command for that:
Batch file to search a keyword in all files of a directory
You may have a different way of accessing the server files. For example, if you have a (SSH) shell access, you can search the files directly on the server. But that's a completely different topic.
I am trying to code a script to automatically process some of our daily ftp files.
I have already coded the files to download from the source ftp using WinSCP and calling it in a .bat file, and would ideally like to call it within the same bat. Scripting Language does not matter, as long as I can run/call it from the original batch.
I need will extract the date from a filename, and unzip the contents into corresponding folders. The source file is delivered automatically daily via FTP, and the filename is:
SOFL_CLAIM_TC201702270720000075.zip
The bolded section is the date that I would like to extract.
The contents of the .zip include two types of content, multiple PDFs and a .dat file.
For the supplied date of 20170227, the pdfs need to get extracted to a folder following the format:
\%root%\FNOIs\2017\02-Feb\02-27-2017
At the same time, the .dat file needs to get extracted to multiple folders following the format:
\%root%\Claim Add\2017 Claim Add\02-2017
\%root2%\vendorFTP\VendorFolder
After extracting, I need to move the source zip to
\%root%\Claim Add\2017 Claim Add\02-2017
What is the best way off accomplishing all of this?
I am assuming it would be the for /f batch command, but I am new to batch coding and cannot figure out how to start it from scratch.
I also have 7zip installed, but do not understand how to use the command-line options.
You have asked for a lot in one question, and not shown any code or demonstrated effort on your part.
For the first part, once you have the filename in a variable:
set FILENAME=SOFL_CLAIM_TC201702270720000075.zip
You can get the date part with:
echo %FILENAME:~13,-14%
The syntax: :13,-14 means "Remove the first 13 letters and the last 14 letters." That should leave you with just the date.
When you integrate that into your script, Show Your Code
I have multiple files whose format of filename like: qs_l2b_yearday.nc; for example: 1s_l2b_2008031.nc.
I'm trying to use shell script to download these files from remote server, but unfortunately I cannot find a way to do that. With my limited understanding the code should loop through years as outside loop and loop through days as inside loop. And the core code should use scp to download the file from server. I have figured out how to download one of those files using scp, but need some help to solve the "for loop" problem.
Year is from 1999 to 2009. Day is from 001 to 365
You can use a wildcard to scp multiple files like so
scp user#somehost:/some/path/to/files/qs_l2b_*.nc /some/target/directory/
I have a batch file that gets files via FTP. I'm able to "mget *", but I only want files that start with any number of numbers, followed by an underscore and then C.
I have:
mget [0-9]*_C*
so, for example, I want to get the file: 01234_C.TXT, but I don't want S01234_C.TXT
what's the syntax for getting a file that starts with numbers?
FTP doesn't support regular expressions.
You would have to log an ftp session and get a list of the files, process that list locally and then create another script to get every file that matchs your filespec.
I'm running the command
rar a -m0 -v100m rarname.rar *.*
On some files with a bash script. I know I specified the rarname, but because of the -v option which sets a size limit to the rar, this command can make lots of rars named rarname.part1.rar, rarname.part2.rar, etc.
What is the best way to get the list of files created?
This should do it:
rarname.*.rar
Globs are not limited to the DOS-style "name.ext" pattern.
You can either capture and parse the output from the rar command or create the rar'ed files in a temporary directory, and then process the files there.
I'd recommend the later option.