Bash script for ftp file transfer

Closed
vbavba - Jan 28, 2010 at 03:32 AM
 dazfinger - Mar 9, 2010 at 08:33 AM
Hello,

I would like to have a script which will run as a scheduled task which will zip a log file on a system and then will transfer the file to a ftp server. This will run as a scheduled task on a daily basis and also will run a similar one for a week base . I have a script written by someone else on which gives different results when ran differently when ran as scheduled task and manual. When its ran as a manual batch the transfered file size seems ok ? (not hardly checked) but when run as a scheduled task the log file transfered size is nearly at %1. Im giving the script
(some data maybe deleted like password etc)

Regards


for /f "tokens=1,2 delims==," %%a in ('C:\cron\omega\yesterday') do (
set p1=%%a
set p2=%%b
)

set ftpScript=C:\temp\tmp_FTPScript.cmd
set fileName=C:\temp\cpDailyLog_%p1%

echo %fileName%.zip C:\windows\fw1\r65\fw1\log\%p2%_*
zip %fileName%.zip C:\windows\fw1\r65\fw1\log\%p2%_*

ping 1.1.1.1 -n 1 -w 900000 > nul

echo open 10.x.x.x > %ftpScript%
echo ftpuser>> %ftpScript%
echo password>> %ftpScript%
echo bin >> %ftpScript%
echo cd logs >> %ftpScript%
echo cd omega >> %ftpScript%
echo cd cp >> %ftpScript%

echo put %fileName%.zip >> %ftpScript%
echo bye >> %ftpScript%

ftp -s:%ftpScript%

ping 1.1.1.1 -n 1 -w 900000 > nul

del %ftpScript%
del %fileName%.zip
Related:

2 responses

Sorry,
The title would be the batch script not bash . The platform is windows 2003

Thanks
1
Set up a linux box and use lmftp from lmftp.sourceforge.net
0
Richard.Williams Posts 25 Registration date Saturday November 7, 2009 Status Member Last seen July 18, 2012 14
Jan 29, 2010 at 09:48 AM
Here is a script that will run on all Windows versions. The script will upload C:\temp\cpDailyLog.txt file to an FTP server daily.

# Script UploadDailyLog.txt
# Input arguments
var str ftpserver, ftplogin, ftppassword
echo $ftplogin "\n" $ftppassword > "C:/ftpcommands.txt"
echo "put \"C:\temp\cpDailyLog.txt\"" >> "C:/ftpcommands.txt"
echo "bye" >> "C:/ftpcommands.txt"
system ftp -s:C:/ftpcommands.txt $ftpserver
system del "C:/ftpcommands.txt"



This script is in biterscripting. Save the script in file "C:/Scripts/UploadDailyLog.txt", then schedule the following command to run daily.


"C:/biterScripting/biterScripting.exe" "C:/Scripts/UploadDailyLog.txt" ftpserver("ftp.myftpserver.com") ftplogin("mylogin") ftppassword("mypassword")
1