PDA

Click to See Complete Forum and Search --> : ftp script - sample code


jim mcnamara
Jun 18th, 2001, 10:20 PM
Consider using ftp scripts instead of the Inet control. Scripts are far faster to implement, and a lot easier to maintain. True of course, If you know the ftp script language, which is dirt simple.

I've developed a s**load of routines, all of which use one vb module, and execute any one of hundreds of scripts to do all sorts of stuff from directory listings to deletes to downloads or uploads.

If you invoke ftp from the command line at the DOS prompt, you can get a little help on all the commands supported. MSDN also has extensive ftp script information.

You invoke a script with code like this --------------


Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Sub ftpGet()
Dim WindowsDir as String, lSiz as Long, retval as Long
Dim cmd$
WindowsDir = Space(255)
retval = GetWindowsDirectory(WindowsDir,lSize)
WindowsDir = left(WindowsDir,lSize)
cmd$ = WindowsDir & "ftp -is:script.ftp"
chdir("scriptdir") ' you must be in the dir where the script lives
Shell cmd$,vbNormalFocus
End Sub


The ftp command line is
ftp -is:script.txt

The -is: == read a script and use mget with no user intervention. This works whether mget is there or not.

You can't put anything but commands in the script, but I've added VB style comments. Remove the comments. Here are about one-third of the commands --- the most-used ones, IMO.


open ftp.somewhere.com ' open the site
username
password ' password & username are case sensitive
lcd \mydir ' change local (PC) directory
cd wherever ' change host path, host syntax
get fullfilename.txt
mget wildcard*.txt ' mget for wild cards
asc ' force ascii mode transfer on UNIX server can't do this with Inet control
bin ' force binary mode transfer
del somefile.txt 'delete host file
mdel *.txt ' wildcard delete host file
ls ' get host directory uses UNIX ls qualifiers
bye ' log off - required


When you exit the script, you will return to the directory you started in - assuming you used lcd.