Pass parameters to ftp

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RMSoares
Posts: 32
Joined: 06 Aug 2012 12:01

Pass parameters to ftp

#1 Post by RMSoares » 22 Aug 2012 05:23

I'm invoking the ftp directly on the batch, where the values of username/ passaword/ paths are defined in the code of the FTP. I intend to pass these values as parameters to the batch, but the parameters appears as null inside of the invoking of ftp.

Actual batch

Code: Select all

@echo off 
setlocal EnableDelayedExpansion

set /p "data="<"%QUADIR%QUA_tmp_datatest_vtest.txt" >nul
ren "%QUADIR%QUA_tmp_datatest_vtest.txt" "FSeq_002_IN_%data:~20,8%_%data:~34,2%%data:~32,2%%data:~28,4%.dat"

@ftp -i -s:"%~f0"&GOTO:EOF
open MY_SERVER
Username
Password
!:--- FTP commands below here ---
cd /usr/wtest/geq/files/IN/
binary
mput FSeq_002_IN_*.dat
disconnect
bye


Questions
1 - The server name, user/ password, directory to put file should be passed to ftp as parameter,i've tried to create the variables before starting the ftp, but within the ftp values appear to null
2 - The name of the file to send is created as rename the file based on the 1st line of the file, how to pass the new name of file into the ftp?

Thank's in advance for your help.

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

Re: Pass parameters to ftp

#2 Post by foxidrive » 22 Aug 2012 05:36

Here is a method.

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set /p "data="<"%QUADIR%QUA_tmp_datatest_vtest.txt" >nul
ren "%QUADIR%QUA_tmp_datatest_vtest.txt" "FSeq_002_IN_%data:~20,8%_%data:~34,2%%data:~32,2%%data:~28,4%.dat"

set file="FSeq_002_IN_%data:~20,8%_%data:~34,2%%data:~32,2%%data:~28,4%.dat"

(
echo open MY_SERVER
echo %1
echo %2
echo cd /usr/wtest/geq/files/IN/
echo binary
echo mput %file%
echo disconnect
echo bye
)>ftp.script


ftp -i -s:ftp.script
del ftp.script

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Pass parameters to ftp

#3 Post by Squashman » 22 Aug 2012 06:05

Didn't Foxidrive show you in your previous thread how to do an FTP script?

Post Reply