MGET for specific file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
slstrozier
Posts: 8
Joined: 24 Jun 2014 07:46

MGET for specific file.

#1 Post by slstrozier » 24 Jun 2014 08:38

I have a few files on an ftp server. The naming convention is something like Area #### BIG File.pdf where #### could be any number between 100 and 2800(with no leading zeros).
Is there a way I can use mget to only get the files between 100 and 999, then get the files that are between 1000 and 2800?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: MGET for specific file.

#2 Post by foxidrive » 24 Jun 2014 12:07

You can use a script to get the files.

It will depend on info on the filename format and how it can vary.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: MGET for specific file.

#3 Post by Aacini » 24 Jun 2014 12:18

Code: Select all

@echo off

for /L %%i in (100,1,999) do if exist "Area %%i BIG.pdf" ECHO Process mget here with file "%%i"
for /L %%i in (1000,1,2800) do if exist "Area %%i BIG.pdf" ECHO Process mget here with file "%%i"

slstrozier
Posts: 8
Joined: 24 Jun 2014 07:46

Re: MGET for specific file.

#4 Post by slstrozier » 24 Jun 2014 12:47

Aacini wrote:

Code: Select all

@echo off

for /L %%i in (100,1,999) do if exist "Area %%i BIG.pdf" ECHO Process mget here with file "%%i"
for /L %%i in (1000,1,2800) do if exist "Area %%i BIG.pdf" ECHO Process mget here with file "%%i"


Thanks for your help, Aacini. but this is not working. Getting 'Invalid Command' error.

foxidrive, the filename format will always be the same, the only thing that will change will be the numbers.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: MGET for specific file.

#5 Post by foxidrive » 25 Jun 2014 02:53

When you create your FTP script, use Aacini's code to generate get statements in the batch file:


Something like this untested code:

Code: Select all

@echo off
(
echo open ftp.server.com
echo username
echo password
echo binary
for /L %%i in (100,1,999)   do echo get "Area %%i BIG.pdf"
for /L %%i in (1000,1,2800) do echo get "Area %%i BIG.pdf"
echo bye
)>ftp.script
ftp -i -s:ftp.script

slstrozier
Posts: 8
Joined: 24 Jun 2014 07:46

Re: MGET for specific file.

#6 Post by slstrozier » 25 Jun 2014 05:46

foxidrive wrote:When you create your FTP script, use Aacini's code to generate get statements in the batch file:


Something like this untested code:

Code: Select all

@echo off
(
echo open ftp.server.com
echo username
echo password
echo binary
for /L %%i in (100,1,999)   do echo get "Area %%i BIG.pdf"
for /L %%i in (1000,1,2800) do echo get "Area %%i BIG.pdf"
echo bye
)>ftp.script
ftp -i -s:ftp.script


Thanks for your reply, but I don't think I am advanced enough to understand what to do to make this work. Ive tried and I get "invalid command'. I haven't had to do much with batch files up to this point.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: MGET for specific file.

#7 Post by foxidrive » 25 Jun 2014 07:21

You have to explain how you have been executing it...

slstrozier
Posts: 8
Joined: 24 Jun 2014 07:46

Re: MGET for specific file.

#8 Post by slstrozier » 25 Jun 2014 08:17

foxidrive wrote:You have to explain how you have been executing it...


I have been using an ftp script. And a pretty simple one at that.

open ftp
user username password
lcd "C:\DownloadLocation"
prompt
for /L %%i in (100,1,999) do echo get "Area %%i BIG.pdf"
for /L %%i in (1000,1,2800) do echo get "Area %%i BIG.pdf"
close
quit

This file is called by a batch file:
ftp -n -s:%ftpfile% >> %log%

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: MGET for specific file.

#9 Post by foxidrive » 25 Jun 2014 08:54

For several reasons yours will not work.

Paste the code I provided into notepad

Change the ftp.server.com and username and password in the lines below and then

Code: Select all

echo open ftp.server.com
echo username
echo password


add a line with pause as the last line.
save it as msdos text format, in a file called FTP-test.bat

Test the batch file.

slstrozier
Posts: 8
Joined: 24 Jun 2014 07:46

Re: MGET for specific file.

#10 Post by slstrozier » 25 Jun 2014 09:07

foxidrive wrote:For several reasons yours will not work.

Paste the code I provided into notepad

Change the ftp.server.com and username and password in the lines below and then

Code: Select all

echo open ftp.server.com
echo username
echo password


add a line with pause as the last line.
save it as msdos text format, in a file called FTP-test.bat

Test the batch file.


Did it and it printed the values to the cmd window and asked 'Press any key to continue'

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: MGET for specific file.

#11 Post by foxidrive » 25 Jun 2014 22:01

This is the code you were meant to be using.

Code: Select all

@echo off
(
echo open ftp.server.com
echo username
echo password
echo binary
for /L %%i in (100,1,999)   do echo get "Area %%i BIG.pdf"
for /L %%i in (1000,1,2800) do echo get "Area %%i BIG.pdf"
echo bye
)>ftp.script
ftp -i -s:ftp.script

slstrozier
Posts: 8
Joined: 24 Jun 2014 07:46

Re: MGET for specific file.

#12 Post by slstrozier » 26 Jun 2014 09:20

foxidrive wrote:This is the code you were meant to be using.

Code: Select all

@echo off
(
echo open ftp.server.com
echo username
echo password
echo binary
for /L %%i in (100,1,999)   do echo get "Area %%i BIG.pdf"
for /L %%i in (1000,1,2800) do echo get "Area %%i BIG.pdf"
echo bye
)>ftp.script
ftp -i -s:ftp.script


Again, thanks for your help. But this command 'for /L %%i in (100,1,999) do echo get "Area %%i BIG.pdf"' is not working. Entered exactly this way gives me an 'invalid command' error. I am using Windows 7.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: MGET for specific file.

#13 Post by foxidrive » 26 Jun 2014 09:31

It works fine here.

This is the same code in a batch file. Try to get that working.

Code: Select all

@echo off
for /L %%i in (100,1,999)   do echo get "Area %%i BIG.pdf"
pause


if you still have problems then let us know which Windows version you are using and describe how you go about executing it.

slstrozier
Posts: 8
Joined: 24 Jun 2014 07:46

Re: MGET for specific file.

#14 Post by slstrozier » 26 Jun 2014 14:05

foxidrive wrote:It works fine here.

This is the same code in a batch file. Try to get that working.

Code: Select all

@echo off
for /L %%i in (100,1,999)   do echo get "Area %%i BIG.pdf"
pause


if you still have problems then let us know which Windows version you are using and describe how you go about executing it.


This is how I call the ftp file:
ftp -n -s:ftpfile.ftp

This is the ftp File:
open ftp.server.com
user user1 P@55Word1
lcd "C:\DownloadFiles"
for /L %%i in (100,1,999) do get if exist "Area %%i BIG.pdf"
close
quit

This is the Result:
ftp> Connected to ftp.server.com.
open ftp.server.com
220 Check Point FireWall-1 Secure FTP server running on CPFW1
ftp> user user1 P@55Word1
331 (not authenticated): Enter server password
230-Connected to server. Logging in...
230-220 Welcome to TheServer FTP
230-331 Password required for user1
230 230 Logged on
ftp> Local directory now C:\.
ftp> lcd "C:\DownloadFiles"
Invalid command.
ftp> for /L %%i in (100,1,999) do get if exist "Area %%i BIG.pdf"
close
221 Goodbye
ftp> quit

I am running Windows 7 Professional

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: MGET for specific file.

#15 Post by foxidrive » 26 Jun 2014 18:25

That shows me that you are expecting a batch file command to work in an FTP script,
and you aren't using the batch file that was provided.

The batch file is meant to be clicked on to launch it. Or you type the batch filename to launch it.
It creates a new FTP script every time it runs, and launches FTP.EXE itself.

You can add a line at the bottom with: del ftp.script
so that it deletes the temporary FTP script when it is done.

Just a tip here - don't call the batch file FTP.bat

Post Reply