Pass variable in FTP batch script

Microsoft Windows xp professional w/serv...
October 20, 2010 at 02:24:52
Specs: Windows XP
Hi,

I have a file (example: file_list.csv) with the delimiter as 'space' like this.

file_list.csv
----------------
batch.txt alpha.txt gamma.txt tera.txt

I need to get all these files from FTP to my local folder.

I'm planning to write a batch script which uses "mget" command to get these files. But how to pass this "file_list.csv" as variable in the batch script? Please help.


See More: Pass variable in FTP batch script

Report •

#1
October 20, 2010 at 04:50:06
@echo off > s.ftp & setLocal EnableDELAYedeXpansion

>> s.ftp echo o mysite
>> s.ftp echo user
>> s.ftp echo pass
>> s.ftp echo bin

set N=

for /f "tokens=* delims= " %%a in (my.csv) do (
call :sub1 %%a
)

for /L %%i in (1 1 !N!) do (
>> s.ftp echo get !V%%i!
)

>> s.ftp echo bye

ftp -s:s.ftp

goto :eof

:sub1
  :loop
    set /a N+=1
    set V!N!=%1
      if '%2' neq '' (
        shift
        goto :loop
      )
goto :eof


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
October 21, 2010 at 02:46:50
Hi M2,

Thank you very much for the script. It gives the output "s.ftp" but that is not getting executed automatically and files are not downloaded.

I have this following script. But it could not handle more files from "list_out.csv" say, 3000 files at a time. It works fine for few list of files say, 100 or so. Please check if there is any possibility to load all 3000 plus files at a time.

@echo off > download.txt & SetLocal EnableDelayedExpansion

>> download.txt echo open mysite
>> download.txt echo user
>> download.txt echo pass
>> download.txt echo bin
>> download.txt echo lcd E:\test
>> download.txt echo cd /test/completed/

set LIST=
For /f "tokens=1* delims= " %%A in (list_out.CSV) Do set LIST=!LIST! %%A
echo mget%LIST% >> download.txt

>> download.txt echo disconnect
>> download.txt echo bye

ftp -i -s:download.txt

Thanks much for your help. :)


Report •

#3
October 21, 2010 at 03:41:32
OK first thing. You say the script I posted doesn't get any files?

Post the s.ftp


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
October 21, 2010 at 03:58:02
Yes, the file got generated as "s.ftp" in the directory but it's not executed automatically and so the files are not downloaded.

This is the sample of generated "s.ftp"

s.ftp
-------
mysite
user
pass
bin
get file1.txt
get file8.txt
get file13.txt
bye

In the script i gave the location as cd, lcd, etc properly.

I manually tried to execute "s.ftp" using command prompt but still the files are not downloaded, but just opened the content of "s.ftp". Please help me out.


Report •

#5
October 21, 2010 at 04:04:23
Paste in the script you're using.

[Replace user and pass with ****.]


=====================================
Life is too important to be taken seriously.

M2


Report •

#6
October 21, 2010 at 04:16:39
open asmi00
****
****
bin
cd /test/completed/
lcd E:\test
get C120.zip
get C154.zip
get C1304.zip
get C1731.zip
get C347.zip
bye

Though i give the "open" command in the 1st line or just the ftp "asmi00", it doesn't help.


Report •

#7
October 21, 2010 at 04:37:10
I'm going crazy. Itz working fine now. Did some touch ups in script. Donno what was wrong before.

Thanks a lot for your help and patience. :) Marvellous M2 !!!


Report •

#8
October 21, 2010 at 04:42:50
Glad we got there. I'm going out the door in 15 and don't like to drop a problem once we got traction.


=====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question