Previous Topic

Next Topic

Book Contents

Book Index

FTPClient Object

The sample script below will access a defined FTP Server. You can change the authentication details.

See also FTPClient documentation under Automation > Automated Miscellaneous.

Note: There is also a SFTPClient Object.

const utNoTLSSupport = 0

const utClearMode = 0
const utUseImplicitTLS = 1
const utUseRequireTLS = 2
const utUseExplicitTLS = 3
Dim FTP as object
FTP = createobject("Accredo.FTPClient")
FTP.host = "MyFTPHost"
FTP.Username = "MyFTPUserName"
FTP.Password = "MyFTPPassword"
FTP.logging = true
FTP.TLSMode = utNoTLSSupport ' if using FTPS, set this to the appropriate mode

FTP.TLSPortSecurity = utClearMode 'if TLSMode = 0, this can be set to 0 = Clear or 1 = Private
FTP.connect
If Not FTP.connected Then Error("Error connecting to FTP server.")
' upload a selected file
sMesg = "Select a Txt File to Push to the FTP Site"
SelectedFile = InputFileOpen("File:", SMesg,"C:\","Text Files(*.txt)|*.txt")
If IsNull(SelectedFile) Then Abort("User pressed cancel")
If SelectedFile <> "" then
  ' extract filename only from fullpath
  FileName = Mid(SelectedFile,InstrRev(SelectedFile,"\") + 1)
  ' specify a directory on the FTP server
  FTP.CurrentDirectory = "\MyDirectory"
  FTP.Put(SelectedFile,FileName)
End If
' download the same file back
DownloadFile = "c:\MyDownloadFile.txt"
FTP.Get(FileName, Downloadfile)
' print contents of FTP Directory
Dim Dir as Object
Dir = FTP.Dir("", True)
For I = 1 to Dir.LineCount
  Print Dir.GetLine(I)
Next
FTP.Quit