PDA

View Full Version : .sh/.bat ftp script


DYN_DaTa
11-21-2005, 08:23 AM
Hi all.

After searching on Google and trying a couple of ideas ... i'm lost. Here we go:

1) There're two machines: one is Unix and the other one is Windows.

2) On Windows machine there're a couple of csv files (inside a folder called 'A') that should be transferred to Unix (to a 'B' folder) through ftp. I can use an .sh script (to 'get' files) or a .bat file (to 'put' files). The script will be executed every 10 minutes, every day. I can't use FlashFXP or other GUI client, only 'shell' scripting.

3) The tricky part is that for each file transferred i should move it to another folder: for each file transfered from 'A' Windows folder to 'B' Unix folder i should move it to 'C' Windows folder (a subdirectory inside 'A' Windows folder). This is to avoid the same file transfer on future script runs.

4) I know how to make a simple .bat ftp script that will upload one file to another host, but i'm really lost at how can i control that one file is transferred and once is transfered, move it to another folder.


Any ideas?.

Thanks in advance for your time.

_panic_
11-21-2005, 03:25 PM
this is fairly easy to do on the unix end, either with a shell script or python client. you might take a peek at the python ftp library, it might provide everything you need to whip up a simple script.

DYN_DaTa
11-22-2005, 06:14 AM
Thanks :).

I'll take a look.

Mouton
11-22-2005, 11:32 AM
md A\todo\
move A\*.* A\todo\
cd /d A\todo\
echo open remove_unix_host remote_port>ftp.instructions
echo username>>ftp.instructions
echo password>>ftp.instructions
echo bin>>ftp.instructions
echo mput *.*>>ftp.instructions
echo quit>>ftp.instructions
ftp -i -s:ftp.instructions
rm ftp.instructions
move *.* A\C\
cd ..
rd todo
??

DYN_DaTa
11-22-2005, 03:14 PM
Nice one, Mouton, i'll try it. Thanks

DYN_DaTa
11-28-2005, 02:38 PM
After a couple of tries i have a little .bat script that works :) :

@echo off
cd /D D:
if exist *.csv (goto si) else exit
:si
move /Y *.csv D:\Externos_Temp
cd /D D:\Externos_Temp
ftp -i -s:D:\script.txt
move /Y *.csv D:\Externos_Final

Being script.txt

open www.some_host.org 2100
some_username
some_password
ascii
mput *.csv
bye

Mouton
11-29-2005, 11:23 AM
You should use:
cd /D D:\
just to make sure you end up in the root directory of the D drive.
(launching the .bat from a subdir of D:\ will not work correctly...)