FTP Batch script help please

February 10, 2011 at 08:32:28
Specs: Windows 7
Hi Everyone

I need to automate a FTP solution, everyday we recieve automated email advising that their is a file waiting for download. The email always comes on a standard template.

We have written a VBS script that will read the email when it comes in and pull out the file name and put it in a txt file in the root of the C:

so now i need to write a batch file that will pull the file name out of the txt file, and put it into my FTP command. I was thinking something along the liones fo this but it doesnt work, can somebody help me!

this is what i have so far.

SETLOCAL
PATH=C:\curl;%PATH%
PUSHD "C:\curl\FileName.txt"
FOR /F "delims=" %%F IN ('MORE ^< "C:\curl\FileName.txt"') DO (
IF EXIST %%F (
curl --SSL --cert C:\curl\certs\cert.pem:password -k ftp://my.url.co.uk/%%F --user name:pass --ftp-account my-ftp-pjt --trace-ascii C:\curl\scripts\retrieved.txt -Q "STRU F" -Q "MODE S" -o C:\recievedfiles\%%F.pgp
PAUSE
ENDLOCAL

So going off the above, Email comes in pulls out file name from email and puts it in FileName.txt in location C:\curl\ (ALREADY DONE THIS)

Now i need to pull file name out and put it in to curl syntax above!

Hope ive explained this well enough.

Thanks in advance


See More: FTP Batch script help please

Report •

#1
February 10, 2011 at 09:36:35
If your FileName.txt just holds the name of the file to be processed, then

@echo off & setlocal
pushd C:\curl
set /P FTPfile=< FileName.txt
if exist "%FTPfile%" (
curl --SSL --cert C:\curl\certs\cert.pem:password -k ftp://my.url.co.uk/%FTPfile% name:pass --ftp-account my-ftp-pjt --trace-ascii C:\curl\scripts\retrieved.txt -Q "STRU F" -Q "MODE S" -o C:\recievedfiles\%FTPfile%
echo.FTP completed
)
pause


Report •

#2
February 10, 2011 at 10:02:11
Hi

I will give this a go, and let you know how i get on, thank you for a quick response, much appreciated.

Lee


Report •

#3
February 10, 2011 at 12:26:19
Hi There,

That worked brilliant, Thanks very much.

Can i ask another?

I will get a text log (retrieved.txt) out of curl when the downloads finished,
Trouble is, each time the scripts run, the file will get overwritten, can i rename the file with a date and time stamp on the end?

Thanks


Report •

Related Solutions

#4
February 10, 2011 at 14:48:12
 
@echo off & setlocal EnableDelayedExpansion
pushd C:\curl
set /P FTPfile=< FileName.txt
if exist "%FTPfile%" (
curl --SSL --cert C:\curl\certs\cert.pem:password -k ftp://my.url.co.uk/%FTPfile% name:pass --ftp-account my-ftp-pjt --trace-ascii C:\curl\scripts\retrieved.txt -Q "STRU F" -Q "MODE S" -o C:\recievedfiles\%FTPfile%
echo.FTP completed
set logdate=!date:~-10!
set logdate=!logdate:/=-!
set logtime=!time:~0,5!
set logtime=!logtime:.=-!
set logtime=!logtime::=-!
set logdate=!logdate!_!logtime!
ren C:\curl\scripts\retrieved.txt retrieved_!logdate!.txt
)
pause


Report •

#5
February 11, 2011 at 10:29:09
Worked first time, once again your help as been greatly appreciated

Mark as well and truly fixed!


Report •

#6
February 14, 2011 at 06:26:59
Hey, is this possible

I have an dropfolder where files can be placed at anytime, these files will be encrypted then uploaded via FTP

I want to poll the dropfolder every 30 seconds for any new files, and react as needed.

So in short

poll C:\dropfolder, if file(s) exists then call SEND_FILE.bat, when send_file.bat has finished go to sleep for 30 seconds, then loop

If files do not exists then sleep for 30 seconds then goto start.

Hope this smakes sense


Report •

#7
February 14, 2011 at 14:01:35
First of all download the following tool (Free - DOS sleep.exe) and store it into C:\Windows\system32

http://www.computerhope.com/dutil.htm

then

@echo off
cd \DropFoldser
:LOOP
  for %%j in (*) do call Send_File %%j
  sleep 30
goto :LOOP

The above calls Send_File for each file detected in the folder passing it on the command tail. If you instead want just to call the subroutine batch without parameters if files exist, then

@echo off
cd \Dropfolder
:LOOP
  if exist *.* call Send_File
  sleep 30
goto :LOOP

Obviously the choice depends on the coding of Send_file.bat

Report •

#8
February 16, 2011 at 01:16:07
Hi

Once again, worked first time, used the second option. Thanks alot!!


Report •

Ask Question