Page 1 of 1

How to create a batch file that will get file from FTP serve

Posted: 02 Oct 2008 05:18
by scorpio
Hi Everyone,

I understand a little on batch programming and write simple batch file.

Right now I have this kind interest on how I can automate my file transfer from FTP server to local folder in my PC using a batch file

This is the command I am always using at my CMD prompt.:

c:\>ftp 10.611.xxx.yyy
Connected to 10.611.xxx.yyy
220 wpxxxgb FTP server (version 1.1.214.4(PHNE_xxxxx) Thu Nov 20 06 06:40:06 GMT 2003) ready.
User (10.611.xxx.yyy:(none)):username - I type in my "username"
331 Password required for username
Password: - type in my password
230 User username logged in.
ftp>
ftp>cd 1103/ar/10.0.23/out - the directory where the data located
250 CWD command successful
ftp>binary
200 Type set to I.
ftp> mget *4035584* - the files I want to get
200 Type set to I
mget EMP057.40xxxx?y
200 PORT command successful
150 Opening BINARY mode data connection for EMP057.40xxxx (29804 byte)
226 Transfer complete.
ftp. 29804 bytes received in 0.69seconds 43.45 Kbytes/sec.
ftp>bye
221 Goodbye.
c:\>

How to I attache the username and password to the ftp command?

Hope you can give tips. Thanks


Then after getting the file, I will move it to the folder d:\DATA\INVOICE

Posted: 07 Oct 2008 00:23
by carlitos.dll

Code: Select all

@echo off
call:options>"%temp%\ftp.ftp"
ftp -s:"%temp%\ftp.ftp" -i>nul 2>&1
del/f/q/a "%temp%\ftp.ftp">nul 2>&1
goto:eof
 
:options
echo open ftp.microsoft.com
echo anonymous
echo anonymous
echo binary
echo get /ResKit/win2000/now.zip
echo close
echo quit
goto:eof

[/code]

Automating FTP command "Get" with listing in text

Posted: 13 Oct 2008 19:26
by scorpio
Hi Carlito,

thanks for this reply and it helps a lot, I successfully automate my login to the ftp but the risk is that I hard coded my username and password into the script.

I have another question, this is still connected with this script. My goal now is to get files from FTP server and my reference of the list of file are listed in a text file (e.g. 4printing.txt) and that text file list contain these information, A selected file to be extracted to the ftp server:

4printing. txt
- User1.12435
- User1.34568
- Invc2.74120
- sysad.12547

Now, is their a way to automate this process, read the text file and feed the content text to a command line

example:
get user1.12435
get User1.34568
get Invc2.74120
get sysad.12547

Hope for your reply and thanks in advance.

Posted: 17 Oct 2008 14:58
by carlitos.dll
The author has been removed this message.

Posted: 19 Oct 2008 12:29
by DosItHelp
Here is a script that resolves environment variables within the FTP script:

Code: Select all

;@echo off
;(for /f "usebackq delims=" %%A in ("%~f0") do call echo.%%A)>"%temp%\%~n0.ftp"
;ftp -i -s:"%temp%\%~n0.ftp"
;GOTO:EOF

open example.com
username
password
!:--- FTP commands below here ---
cd public_html/%COMPUTERNAME%
binary
hash on
%*
disconnect
bye

More details here:
http://www.dostips.com/DtTipsFtpBatchScript.php#Batch_FtpBatchUsingVariables
Hope this is useful. :wink: