FTP Script

I need a script to ftp a file from one server to another server. I also want whenever the file is successfully ftp, it will REMOVE the file to a log directory and rename it based on the date and time it was uploaded.

For example, the file name is ABC.txt and located at c:\batch and after successfully ftp the file will be removed to c:\batch\log and will be named ABC_DDMMMYY_HHMMSS.SUCESSS and if fail the file will be named ABC_DDMMYY_HHMMSS.FAIL.

This script will be put in the schedule task.

Server Name: test.server.com
user: user1
password : abc123

Thanks
RizuanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hypheniCommented:
do this.. username: ss, password: ss
0
Bill PrewCommented:
Can you tell me what the following two commands display on the server where the script will be run?

echo %date%
echo %time%

Also, does this have to be done with the native Windows FTP tool, or could a free third paty FTP tool be used?

~bp
0
RizuanAuthor Commented:
billprew,
Fri 04/09/2010
9:32:20.78

It has to be done with the native Windows FTP tool.

hypheni,
I dont understand your comment.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

giltjrCommented:
What FTP server are  you using?

You are not going to be able to do this using a FTP client.  FTP clients can't "move"  files, there is no move command.

The "moving" of the file will need to be done on the server side and so your FTP server needs to have the ability to trigger a process once a file upload has completed.

Now the client could create an empty file that has the date/time stamp and "SUCCESS" or "FAILED" in the file name.  But you will need either a ftp client that has built in scripting or use something like Perl that can check the results of transfer.
0
Robberbaron (robr)Commented:
the problem i have found with the internal FTP client is the success/fail detection. I dont think it sets an errorlevel.
Only way may be to log all the commands and then process that logfile.

you can script it using
http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23079133.html
http://support.microsoft.com/kb/96269

 
ftp -n -i -s:"%script%" %server% > logfile.txt
'now review the logfile.txt to check for success.

0
BlackAdderDKCommented:
Hi

Here's a script that will do that for you

@ECHO OFF
@ftp -i -s:"%~f0" > ftp.log &GOTO:FILECTRL
open test.server.com
user1
abc123
!:--- FTP commands below here ---
binary
put "c:\batch\ABC.txt"
disconnect
bye

:FILECTRL
set D=%DATE:~0,2%
set M=%DATE:~3,2%
set Y=%DATE:~8,2%
set H=%TIME:~0,2%
set M=%TIME:~3,2%
set S=%TIME:~6,2%
type ftp.log|find "226"
if errorlevel 1 goto FTPERROR
GOTO FTPGOOD

:FTPGOOD
move "c:\batch\ABC.txt" "c:\batch\log\ABC_%D%%M%%Y%_%H%%M%%S%.SUCCESS"
GOTO END

:FTPERROR
move "c:\batch\ABC.txt" "c:\batch\log\ABC_%D%%M%%Y%_%H%%M%%S%.FAIL"
GOTO END

:END
del ftp.log
cls
regards
'Adder


0
BlackAdderDKCommented:
... By the way

All the date/time stuff is made with my native version of windows... you might have to adjust it to yours

regards
'Adder
0
giltjrCommented:
Um, maybe  I am confused about something.  Do you want the files moved/renamed on the ftp server or the client that is initiating the transfer?

I interpreted that you wanted it done on the ftp server.

BlackAdderDK has interpreted that you wanted it done on the ftp client.

If you want this done on the client side, then BlackAdderDK's script will work.

If you want this done on the server side, then you need a server side script.
0
RizuanAuthor Commented:
qiltjr,
yes i want the files moved/renamed on the server and my plan is to include in the scheduled task.
i hv tried the script given by BlackAdderDK and it gave this error:
@ECHO OFF
Invalid command
@ftp -i -s:"%~f0" > ftp.log &GOTO:FILECTRL
Invalid command
it seem that the server unable to recognize the command. Only this part that works.
open test.server.com
user1
abc123
!:--- FTP commands below here ---
binary
put "c:\batch\ABC.txt"
disconnect
bye
0
giltjrCommented:
O.K., which server.  Although they are both "servers", in this instance you have a ftp server and a ftp client.

So, you want to put the files from the ftp client to the ftp server.

After you are done putting the files, do you want to move them from \batch to \batch\log on the ftp client or the ftp server?

The script should work.  Its weird that you are getting invalid command on @ECHO OFF and @FTP.
0
RizuanAuthor Commented:
If i'm ftp from one server to another server can i consider that the server that ftp/upload to another server as ftp server and the receiver as ftp client because the ftp script will be run in the server that uploading the file.

After putting the files, i want them to be moved to batch\log in the ftp server.

This command @ECHO OFF and @FTP does not work if i run thru the script but it works if i run using command prompt.

0
giltjrCommented:
You may consider it server to server, but ftp is a client server application and so one of the computers is considered the ftp server and the other is the ftp client.

O.K.  To help not get things confused lets just use COMP1 and COMP2.  

So, if I understand you correctly you want COMP1 to ftp files to /batch on COMP2.  After the transfer is complete you want to move the files from /batch on COMP2 to /batch/log also on COMP2.

If that is correct, you can't do everything with a script running on COMP1.  COMP1 can have a script that ftp's the file to COMP2.  But, as I stated before, there is no ftp MOVE command.  

To move the files from /batch to /batch/log on COMP2 you need to somehow execute a script on COMP2.

I just tested the script and it works fine.  What suffix did you use for the script name?  It should be either .bat or .cmd.
0
RizuanAuthor Commented:
Actually i want COMP1 to ftp files (in /batch) to COMP2.  After the transfer is complete i want to move the files in COMP1 to log directory (/batch/log) and not in COMP2. The script will be run in COMP1.

I used this way
c:\windows\system32\ftp.exe -s:C:\Folder1\Folder2\runftp.txt
0
BlackAdderDKCommented:
Hi Rizuan

Which version of Windows are you running?

regards
'Adder
0
RizuanAuthor Commented:
Windows Server 2003 R2
0
BlackAdderDKCommented:
Hi Rizuan

I think i figured out what you been doing... you have called the script it self for ftp.cmd or ftp.bat... that is a nogo... try calling it ftpupload.cmd - by the way... changed the variables to fit 2003 native us english

@ECHO OFF
@ftp -i -s:"%~f0" > ftp.log &GOTO:FILECTRL
open test.server.com
user1
abc123
!:--- FTP commands below here ---
binary
put "c:\batch\ABC.txt"
disconnect
bye

:FILECTRL
set D=%DATE:~7,2%
set M=%DATE:~4,2%
set Y=%DATE:~12,2%
set H=%TIME:~0,2%
set M=%TIME:~3,2%
set S=%TIME:~6,2%
type ftp.log|find "226"
if errorlevel 1 goto FTPERROR
GOTO FTPGOOD

:FTPGOOD
move "c:\batch\ABC.txt" "c:\batch\log\ABC_%D%%M%%Y%_%H%%M%%S%.SUCCESS"
GOTO END

:FTPERROR
move "c:\batch\ABC.txt" "c:\batch\log\ABC_%D%%M%%Y%_%H%%M%%S%.FAIL"
GOTO END

:END
del ftp.log
cls

Regards
'Adder
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
File Sharing Software

From novice to tech pro — start learning today.