Need help with FTP Batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jojolino
Posts: 3
Joined: 07 Sep 2009 08:05

Need help with FTP Batch

#1 Post by jojolino » 14 Jul 2010 04:35

Hi!
I tried to get a FTP script running but it stucks and I don't know why. :(
I have read this: http://www.dostips.com/DtTipsFtpBatchScript.php#Batch.FtpBatchUsingVariables

So I create a batch file like this:

Code: Select all

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

open ftpserver
username
password
cd directory1
binary
get filename
disconnect
bye


This batch creates a file FTP.ftp in the directory c:\temp
This ftp file looks good.
But when I run my batch it stucks.
In the DOS window I only see c:\temp\ftp.bat but nothing happens. When I interrupt the batch with crtl+c I can find the FTP.ftp file wich contains the right code but why stucks my batch?
Another question. How can I run the batch with a variable? I try to start it as ftp.bat filename and I replace the command get filename with get %1. But when i do this the FTP.ftp contains get -i, so this comes from the line:
;ftp -i -s:"c:\temp\%~n0.ftp"
How can I use variables wich will be included in the ftp batch?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Need help with FTP Batch

#2 Post by aGerman » 14 Jul 2010 06:18

jojolino

I'm not that familar with ftp, but you have to customize the script and maybe you should append a PAUSE command to see what happens.

Try something like that:

Code: Select all

;@echo off
;set "ftpServer=hostname.com"
;set "uName=YourUserName"
;set "pass=YourPassword"
;set "dir=subfolder"
;set "filename=your.pdf"
;(for /f "usebackq delims=" %%A in ("%~f0") do call echo.%%A)>"c:\temp\%~n0.ftp"
;ftp -i -s:"c:\temp\%~n0.ftp"
;pause
;GOTO:EOF

open %ftpServer%
%uName%
%pass%
cd %dir%
binary
get %filename%
disconnect
bye


This example is for ftp://hostname.com/subfolder/your.pdf, so you have to change it. Username and password too.

Hope that helps.
aGerman

jojolino
Posts: 3
Joined: 07 Sep 2009 08:05

Re: Need help with FTP Batch

#3 Post by jojolino » 15 Jul 2010 02:07

Hi!
I am a German too :mrgreen:

I think I have found the problem. When I start the batch in a directory which is part of a path definition it ends in an endless loop. When I run it in a new created directory it works fine.

Post Reply