Link to home
Start Free TrialLog in
Avatar of weklica
weklica

asked on

Throttle FTP sending batch script

I have a large directory of 500,000 files.  I want to send to another computer via FTP which does some processing.  Because of the processing, I would like to throttle the speed of the send.  

Now, I do at CMD  
ftp> <ipaddres>
username,
password,
bin,
prompt,
mput.  

That will send the entire directory.  However, I would like it to send every file while waiting for 1 second inbetween files.  how can I throttle the send so it waits for one second in between files?

Thanks in advance.
Avatar of Bill Prew
Bill Prew

This should do what you want.  Change the folder as needed, and place the host, user and pswd values in where indicated...

@echo off
setlocal

REM Switch to the folder to xfer
pushd c:\temp

REM Process all files in folder, one at a time
for %%A in ("*.*") do (
  REM FTP file
  (
    echo open [hostname]
    echo [username]
    echo [password]
    echo bin
    echo put %File%
    echo quit
  ) | ftp -n -i

  REM Delay one second between files
  ping 1.1.1.1 -n 1 -w 1000>NUL
)

REM Return to original folder
popd

Open in new window

~bp
Avatar of weklica

ASKER

If I leave in the brackets:

Unknown host [10.202.16.69].
Invalid command.
Invalid command.
Not connected.
Not connected.

Then, If take the brackets out:

Invalid command.
Invalid command.
Local file Remote file Invalid command.
You don't want the brackets.

Try this, different FTP servers require slightly different connect sequences.

    echo open [hostname]
    echo user [username] [password]

~bp
Avatar of weklica

ASKER

Hmmm.  Still not working.  However,
I have an FTP script that writes a little text file that I use to access.  This works well, but again, a whole directory at a time.... maybe this way could work.  I would prefer your way, but I don't want to be too bothersome.  Thanks!

echo %MYVAR42%>c:\Directory\DICOM_FILES\tempscriptfile1.txt
echo %MYVAR43%>c:\Directory\DICOM_FILES\tempscriptfile2.txt
echo bin>c:\Directory\DICOM_FILES\tempscriptfile3.txt
echo prompt>c:\Directory\DICOM_FILES\tempscriptfile4.txt
echo prompt>c:\Directory\DICOM_FILES\tempscriptfile5.txt
echo mput *.*>c:\Directory\DICOM_FILES\tempscriptfile6.txt
echo disconnect>c:\Directory\DICOM_FILES\tempscriptfile7.txt
echo bye>c:\Directory\DICOM_FILES\tempscriptfile8.txt
cd\
cd Directory\DICOM_FILES
copy /b /y tempscriptfile1.txt+tempscriptfile2.txt+tempscriptfile3.txt+tempscriptfi
le4.txt+tempscriptfile5.txt+tempscriptfile6.txt+tempscriptfile7.txt+temp
scriptfile8.txt DICOM_FILESscript.txt
ftp -i -s:DICOM_FILESscript.txt %MYVAR44%
Avatar of weklica

ASKER

OK.  So, this works ALMOST:  the code below shows a version that works except it doesn't do the echo put %File% to the tempscriptfile6.txt file.  I know this is a train-wreck way to do it, but it is the only way I know how.  

So, is there a way to write put %File% to a text file since ECHO doesn't let %File% work after it?

@echo on
setlocal

REM Switch to the folder to xfer
pushd d:\Sandbox

REM Process all files in folder, one at a time
for %%A in ("*.*") do (
  REM FTP file
  (
del /q c:\tempscriptfile*txt
del d:\Sandbox\DICOM_FILESscript.txt
echo cd_importer>c:\tempscriptfile1.txt
echo cd_importer>c:\tempscriptfile2.txt
echo bin>c:\tempscriptfile3.txt
echo prompt>c:\tempscriptfile4.txt
echo prompt>c:\tempscriptfile5.txt
echo put %File%>c:\tempscriptfile6.txt
echo disconnect>c:\tempscriptfile7.txt
echo bye>c:\tempscriptfile8.txt
pause
c:
cd\
copy/b /y tempscriptfile1.txt+tempscriptfile2.txt+tempscriptfile3.txt+tempscriptfile4.txt+tempscriptfile5.txt+tempscriptfile6.txt+tempscriptfile7.txt+tempscriptfile8.txt DICOM_FILESscript.txt
copy c:\DICOM_FILESscript.txt d:\Sandbox
d:
cd\
cd Sandbox
ftp -i -s:DICOM_FILESscript.txt 10.202.16.69
  )

  REM Delay one second between files
  ping 1.1.1.1 -n 1 -w 1000>NUL
)

REM Return to original folder
popd

Open in new window

How about something like this:

@echo off

pushd d:\sandbox

for %%a in (*.*) do (
  call :makescript "%%a"
  ftp -i -s:"%temp%\script.txt" 10.202.16.69
  call :wait_1
)

del "%temp%\script.txt"
popd
exit /b


:makescript
  (
    echo cd_importer
    echo cd_importer
    echo bin
    echo prompt
    echo prompt
    echo put "%~1"
    echo disconnect
    echo bye
  )>"%temp%\script.txt"
goto :eof


:wait_1
  ping 1.1.1.1 -n 1 -w 1000>NUL
goto :eof

Open in new window

SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just a thought here: 500,000 sleeping seconds divided by 86,400 seconds in a day means that your script will run for around 6 days, excluding FTP/batch time needed. You can modify the "ping 1.1.1.1 -n 1 -w 1000>NUL" to 500 to sleep half a second....
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Interesting, since at this point they should be doing pretty much the same thing.

~bp
What does "cd_importer" do?

And why do you do two "prompt" commands?  My understanding is that is a toggle command, so doing 2 is the same as doing none, right? Puts you back in whatever state you start in.

~bp
Avatar of weklica

ASKER

cd_importer represents both the username and password to the FTP server.
Avatar of weklica

ASKER

My solution is what I am using, but billprew's is more elegant and I always appreciate his help.
Thanks!

~bp