Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for ftpdir.bat

(view source code of ftpdir.bat as plain text)

  1. @ECHO OFF
  2. SETLOCAL
  3. :: Modify variables as needed
  4. SET FtpSite=ftp.myownsite.com
  5. SET FtpUser=myftpuserid
  6. SET RemoteDir=www
  7.  
  8. :: Check if password is specified on command line
  9. IF X%1==X GOTO Syntax
  10.  
  11. :: Create temporary ftp script:
  12. :: User ID
  13. > %Temp%.\%~n0.ftp ECHO %FtpUser%
  14. :: Password (as specified on command line)
  15. >>%Temp%.\%~n0.ftp ECHO %1
  16. :: Go to directory
  17. >>%Temp%.\%~n0.ftp ECHO cd %RemoteDir%
  18. :: Dir command
  19. >>%Temp%.\%~n0.ftp ECHO dir
  20. :: Quit
  21. >>%Temp%.\%~n0.ftp ECHO bye
  22.  
  23. :: Execute the temporary ftp script
  24. FTP -s:%Temp%.\%~n0.ftp %FtpSite%
  25.  
  26. :: For the paranoid: thoroughly destroy the temporary
  27. :: ftp script because it contains the password:
  28. :: [1] Overwrite its content
  29. ECHO.> %Temp%.\%~n0.ftp
  30. FOR /L %%A in (1,1,1000) DO ECHO.>>%Temp%.\%~n0.ftp
  31. :: [2] Reduce file size to 0 bytes
  32. TYPE NUL > %Temp%.\%~n0.ftp
  33. :: [3] Delete the file
  34. DEL %Temp%.\%~n0.ftp
  35.  
  36. :: Done
  37. GOTO End
  38.  
  39. :Syntax
  40. ECHO.
  41. ECHO FtpDir.bat,  Version 1.01 for Windows NT 4 / 2000
  42. ECHO List files on a (remote) FTP site
  43. ECHO.
  44. ECHO Usage:  %~n0  password
  45. ECHO.
  46. ECHO "password" is the password to get access to the remote FTP site.
  47. ECHO.
  48. ECHO This batch file demonstrates the use of FTP scripts.
  49. ECHO It can be used in other OS versions too with a few minor modifications.
  50. ECHO You will need to modify this batch file's variables section before using it.
  51. ECHO.
  52. ECHO Written by Rob van der Woude
  53. ECHO http://www.robvanderwoude.com
  54.  
  55. :End
  56. ENDLOCAL
  57.  

page last uploaded: 2017-04-06, 13:33