Visual Basic Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Delphi ActiveXDelphi DLLVisual FoxProJavaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerShellPythonRubySQL ServerUnicode CUnicode C++Visual Basic 6.0VB.NETVBScript

VB Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SFTP
SMTP
Socket
Spider
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
Bzip2
PPMD
Deflate
LZW


VB Strings
VB Byte Array

 

 

 

 

 

 

 

FTP Active vs. Passive Transfers

Visual Basic 6.0 example to discuss active vs. passive FTP data transfers.

    ' VB6 sample code discussing the difference between active
    ' and passive FTP data transfers.
    
    Set ftp = New ChilkatFtp2
    success = ftp.UnlockComponent("anything for 30-day trial")
    If (success = 0) Then
        MsgBox "Failed to unlock component!"
        Exit Sub
    End If
    
    ftp.HostName = "ftp.chilkatsoft.com"
    ftp.Username = "***"
    ftp.Password = "***"
    
    ' Turn on session logging.
    ftp.KeepSessionLog = 1
    
    success = ftp.Connect()
    If (success = 0) Then
        MsgBox ftp.LastErrorText
        Exit Sub
    End If
    
    success = ftp.ChangeRemoteDir("test")
    If (success = 0) Then
        MsgBox ftp.LastErrorText
        Exit Sub
    End If
    
    ' Set our transfer mode to passive.
    ftp.Passive = 1
    
    remoteFilename = "pigs.xml"
    localFilename = "c:\temp\pigs.xml"
    
    ' Do the FTP upload in passive mode.
    success = ftp.PutFile(localFilename, remoteFilename)
    If (success = 0) Then
        MsgBox ftp.LastErrorText
        Exit Sub
    End If
    
    ' Now set the transfer mode to active.
    ftp.Passive = 0
    
    remoteFilename = "pigs2.xml"
    localFilename = "c:\temp\pigs.xml"
    
    ' Do the FTP upload again, but this time in active mode.
    success = ftp.PutFile(localFilename, remoteFilename)
    If (success = 0) Then
        MsgBox ftp.LastErrorText
        Exit Sub
    End If
    
    ftp.Disconnect
    
    ' Examine the session log to see the difference between active
    ' and passive.
    Text1.Text = ftp.SessionLog

***
The session log:

220 Serv-U FTP Server v6.3 for WinSock ready...
.
USER chilkatsoft.com
331 User name okay, need password.
.
PASS ****
230 User logged in, proceed.
.
TYPE I
200 Type set to I.
.
CWD test
250 Directory changed to /test
.
PASV
227 Entering Passive Mode (168,144,70,227,218,16)
.
STOR pigs.xml
150 Opening BINARY mode data connection for pigs.xml.
226 Transfer complete.
.

Note: With a passive connection, the server listens on a socket at a randomly selected
port and the client connects. With an active connection, the client listens on a socket
and the server initiates the data connection. We can see here in the session log that
the client has chosen the port number for the data transfer because it sends a PORT
command to the FTP server, providing the information the server needs to establish
the TCP/IP data connection with the client.

PORT 192,168,1,103,14,245
200 PORT Command successful.
.
STOR pigs2.xml
150 Opening BINARY mode data connection for pigs2.xml.
226 Transfer complete.
.
QUIT
221 Goodbye!

 

© 2000-2013 Chilkat Software, Inc. All Rights Reserved.