General
cancel
Showing results for 
Search instead for 
Did you mean: 

Passing parameter to Ftp Script

SOLVED
Go to solution
Vibhor Kumar Agarwal
Esteemed Contributor

Passing parameter to Ftp Script

Hi,

I am automating an Ftp task.
Done mainly, just need to pass an parameter, which i am unable to do.

What i am doing is:


ftp -s:Input_file hostname


username
password
commnad
bye

In the command i want to transfer one file.
This file will be given at the command prompt while calling that Ftp_Automate.bat so that it can be a general one.

Now how do i do this?
Vibhor Kumar Agarwal
6 REPLIES
Ivan Ferreira
Honored Contributor

Re: Passing parameter to Ftp Script

This will work:



echo put %1 | ftp -s:Input_file hostname



username
password

Then run:

Ftp_automate.bat filename_to_put
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Passing parameter to Ftp Script

Oops,

I am unable to get that in place.


echo put %1 | ftp -s:Input_file hostname



username
password

Then run:
Ftp_automate.bat filename_to_put

Now where will it put the file.
I also need to do a cd, because the location is different.
Also it simpy echoes the whole line and not doing a Ftp.

Thanks
Vibhor Kumar Agarwal
Ivan Ferreira
Honored Contributor
Solution

Re: Passing parameter to Ftp Script

Then, try something like this:



echo user username > Input_file
echo password >> Input_file
echo cd %1 >> Input_file
echo put %2 >> Input_file
echo bye >> Input_file
ftp -n -s:Input_file hostname


Then use like this:

Ftp_automate.bat directory file
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Jon Finley
Honored Contributor

Re: Passing parameter to Ftp Script

Ivan's got a good example. I would add to it, some error checking and a Usage example though.
-------------------
@echo off
rem ..: ftp_automate.bat
rem ..: Automates FTP of system files
rem ..: files needed ftp_automate.bat, Input_file
rem ..:----------------------------------

if %2!==! goto error
echo user username > Input_file
echo password >> Input_file
echo cd %1 >> Input_file
echo put %2 >> Input_file
echo bye >> Input_file
ftp -n -s:Input_file hostname
goto done
:error
echo Usage: ftp_automate directory filename
:done
rem ..:---------------------------------

Jon
"Do or do not. There is no try!" - Yoda
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Passing parameter to Ftp Script

Great guys,

It works now.
But i think there must be a formal way of passing parameters rather than echoing :-)
Vibhor Kumar Agarwal
ftp
Occasional Visitor

Re: Passing parameter to Ftp Script

Hi All,
I would like your help.

I´m trying to automate my FTL process but every script or solution that I have seen in the WEB tells me to create a file with user and password inside.

I´m not allowed to create a file with user and password, so I have to use a parameter to do a FTP.

I have tryed to create a bat like this:
ftp -i dsv075
%1
%2
pause
lcd %dirlcd%
cd %dircdput%
binary
prom
......

But the script ask me always the user and password without use %1 and %2.

Do you have any idea?

Thank you very much and it is urgent.

Gustavp