a php developer weblog

blog Closed!
calin view of the web development world

2005/8/18

windows ftp tunnel: two push and pull *.bat scripts

@ 01:58 PM (33 months, 9 days ago)

Most likely you hardly ever need to synchronize a local windows folder to some FTP directory. Even if you do need to do this, there are a bunch of utilities out there already that make this task easy. One example is netdrive, a really useful tool. In case you don't have administrative rights, or care to do things the geek way and have more control, here's two simple BAT scripts that can help you.

These scripts create a windows ftp tunnel. You need to follow these steps:

1. create a directory on your desktop called tunnel; this dir will be synchronized to the ftp directory.
2. On the ftp account, create another directory called again tunnel.
3. Now create a third directory on C:\tunnel.

If you hate so many tunnel names, change the dir names directly in the scripts.

4. Install this push script under C:\tunnel\push.bat:

  1. @echo off
  2. c:
  3. cd "c:\Documents and Settings\<<username>>\Desktop\tunnel"
  4. >  C:\tunnel\script.txt echo open <<xxx.xxx.xxx.xxx>>
  5. >> C:\tunnel\script.txt echo <<ftp_username>>
  6. >> C:\tunnel\script.txt echo <<ftp_pass>>
  7. >> C:\tunnel\script.txt echo cd tunnel
  8. >> C:\tunnel\script.txt echo binary
  9. >> C:\tunnel\script.txt echo lcd C:\
  10. >> C:\tunnel\script.txt echo lcd "c:\Documents and Settings\<<username>>\Desktop\tunnel"
  11. FOR %%A IN (*.*) DO >> C:\tunnel\script.txt echo put %%A
  12.  
  13. >> C:\tunnel\script.txt echo bye
  14. ftp.exe -s:C:\tunnel\script.txt
  15.  
  16. @rem del /Q *.*
  17. del C:\tunnel\script.txt
  18. exit

5. Install the pull script under C:\tunnel\pull.bat containg:

  1. @echo off
  2. c:
  3. cd "c:\Documents and Settings\<<username>>\Desktop\tunnel"
  4. >  C:\tunnel\script.txt echo open <<xxx.xxx.xxx.xxx>>
  5. >> C:\tunnel\script.txt echo <<ftp_username>>
  6. >> C:\tunnel\script.txt echo <<ftp_pass>>
  7. >> C:\tunnel\script.txt echo cd tunnel
  8. >> C:\tunnel\script.txt echo binary
  9. >> C:\tunnel\script.txt echo lcd C:\
  10. >> C:\tunnel\script.txt echo lcd "C:\Documents and Settings\<<username>>\Desktop\tunnel"
  11. >> C:\tunnel\script.txt echo prompt n
  12. >> C:\tunnel\script.txt echo mget *.*
  13. @rem >> C:\tunnel\script.txt echo mdel *.*
  14. >> C:\tunnel\script.txt echo bye
  15. ftp.exe -s:C:\tunnel\script.txt
  16. del C:\tunnel\script.txt
  17. exit

6. Replace all variables with the right values (local windows username, ftp server or ip, ftp user name and pass)
7. Create nice shortcuts on the desktop to these scripts and name them properly.

How to use the ftp tunnel:

  • drag or copy something on the local tunnel dir on your desktop
  • call the push.bat shortcut to "push" the content of the dir to the ftp tunnel dir.

or:

  • copy something on the ftp dir
  • call the pull.bat to download the content of that dir on your desktop


Notices:

  • In step 4, line 16 only remove the @rem part when you are absolutelly sure that you are on your desktop's tunnel dir (therefore after pushing the files, they will be locally deleted).
  • after making sure that the files are properly downloaded, uncomment line 13 of the pull.bat to clean the ftp dir.

The scripts are license free. Install and run them at your own risk! They are rather rudimentary, I run them at work under Windows XP, and they do what they should. But if something breaks on your end, don't blame me.