MGET for specific file.
Moderator: DosItHelp
-
- Posts: 8
- Joined: 24 Jun 2014 07:46
MGET for specific file.
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?
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?
Re: MGET for specific file.
You can use a script to get the files.
It will depend on info on the filename format and how it can vary.
It will depend on info on the filename format and how it can vary.
Re: MGET for specific file.
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"
-
- Posts: 8
- Joined: 24 Jun 2014 07:46
Re: MGET for specific file.
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.
Re: MGET for specific file.
When you create your FTP script, use Aacini's code to generate get statements in the batch file:
Something like this untested code:
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
-
- Posts: 8
- Joined: 24 Jun 2014 07:46
Re: MGET for specific file.
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.
Re: MGET for specific file.
You have to explain how you have been executing it...
-
- Posts: 8
- Joined: 24 Jun 2014 07:46
Re: MGET for specific file.
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%
Re: MGET for specific file.
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
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.
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.
-
- Posts: 8
- Joined: 24 Jun 2014 07:46
Re: MGET for specific file.
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 thenCode: 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'
Re: MGET for specific file.
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
-
- Posts: 8
- Joined: 24 Jun 2014 07:46
Re: MGET for specific file.
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.
Re: MGET for specific file.
It works fine here.
This is the same code in a batch file. Try to get that working.
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 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.
-
- Posts: 8
- Joined: 24 Jun 2014 07:46
Re: MGET for specific file.
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
Re: MGET for specific file.
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
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