Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduled FTP, move uploaded files to created folder

Status
Not open for further replies.

jongag1

Technical User
Feb 1, 2002
65
NL
Hello,

I hope this is the right forum to ask the following.

I am looking for a solution which can do the following:
- upload all files in a certain directory on a scheduled time
- move the succesfully uploaded files to a newly created folder in the following format "uploadedYYYYMMDD" (example uploaded20050623)
- send an email report to one ore more than one email addresses

I asked the people of proFtp if it is possible, but I haven't had a response yet.
Hope someone has an idea about this and can help me.

Kind regards,
Age
 
jongag1,
you could do this with a .bat file and blat to email. then just put the bat file in a scheduled task. google for ".bat"+"ftp" to get some ideas and then get a copy of blat. if you are still stuck, just post again & i'll try to help.
hth
regards,

longhair
 
jongag1,
did you find your answer? if not i can post some code to get you going.
regards,
longhair
 
Hello Longhair,

Sorry for getting back this late.
When I did a Google as you reguested I found a program called Robo-Ftp.
It seems to be able to do what I want, I downloaded the trial version and gave it a try. I am affraid my skills are just not good enough to get it to do what I want...

I also found soma bat examples, but I cannot find anyone which can created a new folder and move the succesfully uploaded files to it.
So I am very curious to see your code.

Kind regards,
Age
 
jongag1,

this should get you going. you will need to get a copy of blat (it's free just google for it). in the code below :: is just like REM. So you will need to put in your proper data, just post with questions.
Code:
@echo off
for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set weekday=%%a& set day=%%b& set month=%%c& set year=%%d)
cd c:\batch scripts\test ::local folder
@echo user ::username ::password>putlog.txt  ::replace ::user ::password with correct
@echo binary>>putlog.txt
@echo mkdir /%year%%month%%day%>>putlog.txt
@echo cd /%year%%month%%day%>>putlog.txt
@echo put ::your file name here >>putlog.txt  ::replace ::your...with correct
@echo put ::another file name here >>putlog.txt ::replace ::another...with correct
@echo bye >>putlog.txt
ftp -n -d -s:putlog.txt 0.0.0.0 :: replace 0's with correct ip
::directory with blat\blat - -body ::"email body in quotes" -to ::email to who -subject ::"email subject" -f ::from -i ::on behalf -server ::ip of mail server -replyto ::email address -noh -attach ::filename
hth
regards,
longhair
 
Hello longhair,

Thanks for your piece off code.
I haven't tested the blat yet, but started with the ftp part off it.
Now there is a
'@echo put for each file name'

The problem for me is that on monday there can be 10 files in the 'upload' dir, on tuesday 8, on wednesday 23 etc.
So best for me is to be able to enter a directory in the script and the script will upload all files in it.
Is it possible to use wildcards?

Regards,
Age
 
Try using "dir /b >filelist.txt" on your source directory.
Now you can use filelist.txt as your input.

For example:
dir /b *.txt >filelist.txt
for /f %i in (filelist.txt) do MyFTP.cmd %i

executes "MyFTP.cmd" batchfile for every txt file in the current directory.
When running this within a batch file, use

dir /b *.txt >filelist.txt
for /f %%i in (filelist.txt) do MyFTP.cmd %%i

In MyFTp.cmd you can issue the FTP and Blat commands.

See also "dir /?" and "for /?"

HTH
 
Allright, so something like this?

Start.bat
Code:
cd Z:\record\good
dir /b *.WAV >filelist.txt
for /f %i in (filelist.txt) do upload.cmd %%i

Upload.cmd
Code:
@echo off
for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set weekday=%%a& set day=%%b& set month=%%c& set year=%%d)
cd Z:\record\good
@echo user username password>putlog.txt
@echo binary>>putlog.txt
@echo mkdir /upload%year%%month%%day%>>putlog.txt
@echo cd /upload%year%%month%%day%>>putlog.txt
@echo put *.WAV>>putlog.txt
@echo bye >>putlog.txt
ftp -n -d -s:putlog.txt 125.124.123.122
::directory with blat\blat - -body ::"email body in quotes" -to ::email to who -subject ::"email subject" -f ::from -i ::on behalf -server ::ip of mail server -replyto ::email address -noh -attach ::filename

If I would use blat, wont I get an email for each uploaded file?

Age
 
jongag1,

no, you'll only get one email, unless you put the blat execute statement in a loop. which is what you have now. what i would do is put the
Code:
dir /b *.WAV >filelist.txt
for /f %i in (filelist.txt) do upload.cmd %%i
in your upload command and do something like
Code:
@echo off
for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set weekday=%%a& set day=%%b& set month=%%c& set year=%%d)
cd Z:\record\good
dir /b *.WAV >filelist.txt
...
for /f %i in (filelist.txt) do @echo put %%i>>putlog.txt
...
not sure if that is the exact syntax but you get the idea.
regards,
longhair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top