Promotic
WikipediaLinkedInYoutubeTwitterFacebook

Example of file transfer by FTP (ActiveX)

This is an example of the transfer of files over the the Intranet/Internet by the FTP protocol. Usage of the ChilkatFTP ActiveX objektu is presumed. It can be downloaded from the manufacturer's web pages: www.chilkatsoft.com/downloads.asp. The manufacturer also offers usage examples at: www.example-code.com/vbscript/ftp.asp. And the interface documentation has been published at: www.chilkatsoft.com/refdoc/xChilkatFtpRef.html.
 
The technology used here is launched in the synchronous mode, therefore it will be handy to use the PmSequencer object for connection and file transfer in the PROMOTIC system. There is an instance created in the script to this object using the CreateObject VB script method.
 
The script for sending the file to the FTP server in the passive transfer mode.:
Dim oftp, success, localFilename, remoteFilename
  
Set oftp = CreateObject("ChilkatFTP.ChilkatFTP.1")
  
oftp.Hostname = "nameserver"
oftp.Username = "*****"
oftp.Password = "*****"
  
' The default data transfer mode is "Active" as opposed to "Passive".
' Change it to Passive by setting the Passive property:
oftp.Passive = 1
  
' Connect and login to the FTP server.
success = oftp.Connect()
If (success <> 1) Then
  MsgBox oftp.LastErrorText
Else
  
  ' Change to the remote directory where the file will be uploaded.
  success = oftp.ChangeRemoteDir("/FTP")
  If (success <> 1) Then
    MsgBox oftp.LastErrorText
  Else
  
    ' Upload a file.
    localFilename = "c:\uplist.txt"
    remoteFilename = "uplist.txt"
  
    success = oftp.PutFile(localFilename,remoteFilename)
    If (success <> 1) Then
      MsgBox oftp.LastErrorText
    Else
      oftp.Disconnect
      MsgBox "File Uploaded!"
    End If
  End If
End If
 
The script for downloading the file from the FTP server in the passive transfer mode.:
Dim oftp, success, localFilename, remoteFilename
  
Set oftp = CreateObject("ChilkatFTP.ChilkatFTP.1")
  
oftp.Hostname = "nameserver"
oftp.Username = "*****"
oftp.Password = "*****"
  
' The default data transfer mode is "Active" as opposed to "Passive".
' Change it to Passive by setting the Passive property:
oftp.Passive = 1
  
' Connect and login to the FTP server.
success = oftp.Connect()
If (success <> 1) Then
  MsgBox oftp.LastErrorText
Else
  
  ' Change to the remote directory where the file will be uploaded.
  ' This step is only necessary if the file is not in the root directory for the FTP account.
  success = oftp.ChangeRemoteDir("/FTP")
  If (success <> 1) Then
    MsgBox oftp.LastErrorText
  Else
  
    ' Download a file
    localFilename = "c:\uplist.txt"
    remoteFilename = "uplist.txt"
  
    success = oftp.GetFile(remoteFilename,localFilename)
    If (success <> 1) Then
      MsgBox oftp.LastErrorText
    Else
      oftp.Disconnect
      MsgBox "File Download!"
    End If
  End If
End If
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice