How to mget files starting with a number in batch FTP - windows

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.

Related

How to use mget to ftp files containing specific string?

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.

How to get file count over ftp server

As we all know, "WC -l" command is used to get number of lines of a file,but i couldn't able to use the same command over ftp server.
Please help me out with this.
You can't run arbitrary shell commands over FTP, you can only run those commands the FTP server accepts.
I'm not aware of any common FTP commands to get the line count of a file. You may want to use SSH instead if possible. Otherwise, you would have to download the file to get the line count.

Download a file from ftp subdirectories using cmd script

I was trying to download multiple files from our ftp server using the script:
mget cd\dir_here\subdir_here\sample*.txt
but it didn't work so I tried to change to back slash:
mget cd/dir_here/subdir_here/sample*.txt
a message
Type set to A
appeared. What does that mean?
Type set to A
This means that you've told the FTP server you will be transferring by ASCII.
You almost never actually want to do ASCII, it is better to make a habit of using Binary for all transfers. (ASCII breaks the chain of custody, ASCII transfers can modify file contents such as changing New line characters and not sending correct Unicode characters and are completely unsuited to binary file contents, while the speed benefits are trivial.)
You want to make sure your FTP script uses commands separately it looks like you put a CD along with an MGet here...?
Example FTP Script:
user USERNAME PASSWORD
binary
lcd C:\Local\File\System\Folder
cd /root/dir_here/subdir_here
mget sample*.txt
quit
This would be in a script file which would be specified in the FTP command when you call it from the command line or from a script.
eg:
ftp -n -i -v "-s:C:\Local\Path\To\FTP\Script.txt" SERVER_IP

How to extract date from filename in batch, and unzip to multiple directories using batch/7z

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

Loop through files in a FTP using MS DOS

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.

Resources