Solved

Send file via ftp in VB6

Posted on 2011-03-09
6
604 Views
Last Modified: 2012-05-11
How could I send a file to an ftp server via VB6?  Is this possible?
0
Comment
Question by:hrolsons
6 Comments
 
LVL 11

Expert Comment

by:kbirecki
ID: 35091529
Like many things, there are multiple methods.  One would be to use shell commands, effectively sending your commands to a DOS command instance.  Probably not a fun way to do this.  Another way would be to use something like this class:
http://www.vbforums.com/showthread.php?t=278027

If that doesn't suit your needs, a quick Google search on "vb6 ftp" will turn up oodles of options.
0
 

Author Comment

by:hrolsons
ID: 35091611
Thanks kbirecki, I did find that script you referenced, but saw the date of 2004 and was put off.  But, come to think of it, VB6 and 2004 go hand in hand.  Some day I'll move into the next generation, but for now, I'm comfortable.
0
 
LVL 11

Expert Comment

by:kbirecki
ID: 35093407
same for me.  I still use it too.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Accepted Solution

by:
MedievalWarrior earned 500 total points
ID: 35094086
Have a look at this thread http:Q_26291032.html#33092339 you can add the code to a module.
0
 
LVL 10

Expert Comment

by:cool12399
ID: 35095595
Yes,

You can do FTP in VB6. It is very easy.

Here is an example (taken from here: http://www.eggheadcafe.com/authorcodesamples/20010821.zip)
Just plug & play.






'  Here's the code for frmFTP

Option Explicit

Private msCurrentFile As String
  
Friend Sub FTPFile(ByVal sFTPServer As String, _
                   ByVal sFTPCommand As String, _
                   ByVal sFTPUser As String, _
                   ByVal sFTPPwd As String, _
                   ByVal sFTPSrcFileName As String, _
                   ByVal sFTPTgtFileName As String)
 
 Dim oFS As Scripting.FileSystemObject
 Dim sURL As String
 
 On Error GoTo FTPFileExit
 
 Me.HRG True
 msCurrentFile = ""
 
 Set oFS = New Scripting.FileSystemObject
  
    sURL = "ftp://" & sFTPServer
    
    Inet1.Protocol = icFTP
    Inet1.RequestTimeout = 60
    Inet1.RemotePort = 21
    Inet1.AccessType = icDirect
    Inet1.URL = sURL
    Inet1.UserName = sFTPUser
    Inet1.Password = sFTPPwd
   
    
   Select Case sFTPCommand
 
          Case "PUT"
              
                msCurrentFile = sFTPSrcFileName
                If oFS.FileExists(sFTPSrcFileName) = False 
                  Then GoTo FTPFileExit
                Inet1.Execute sURL, sFTPCommand & Space(1) &
                  sFTPSrcFileName & " " & sFTPTgtFileName
                       
          Case "GET"
              
                msCurrentFile = sFTPTgtFileName
                If oFS.FileExists(sFTPTgtFileName) = True Then 
                   oFS.DeleteFile sFTPTgtFileName, True
                end if
                Inet1.Execute sURL, sFTPCommand & Space(1) & 
                     sFTPSrcFileName & " " & sFTPTgtFileName
        
    End Select
    
    
    Me.WaitForResponse
    Inet1.Execute sURL, "quit"
    Me.WaitForResponse
 
  
FTPFileExit:
  Set oFS = Nothing
  HRG False
End Sub
 

Friend Sub WaitForResponse()

  Dim fWait As Boolean
  
  On Error GoTo ErrHandler
 
  fWait = True
  Do Until fWait = False
        DoEvents
        fWait = Inet1.StillExecuting
  Loop
 
ErrHandler:
  Err.Clear
End Sub
 
Private Sub Inet1_StateChanged(ByVal State As Integer)
 
    On Error Resume Next
    
    Select Case State
           Case icNone
           Case icResolvingHost:  
               Me.lblRESPONSE.Caption = "Resolving Host"
           Case icHostResolved:  
               Me.lblRESPONSE.Caption = "Host Resolved"
           Case icConnecting:    
                Me.lblRESPONSE.Caption = "Connecting..."
           Case icConnected:      
               Me.lblRESPONSE.Caption = "Connected"
           Case icResponseReceived: 
                Me.lblRESPONSE.Caption = "Transferring File..."
           Case icDisconnecting:          
               Me.lblRESPONSE.Caption = "Disconnecting..."
           Case icDisconnected:          
                  Me.lblRESPONSE.Caption = "Disconnected"
           Case icError: 
               MsgBox "Error:" & Inet1.ResponseCode & " " & Inet1.ResponseInfo
           Case icResponseCompleted:  
              Me.lblRESPONSE.Caption = "Process Complete."
     End Select
      
         Me.lblRESPONSE.Refresh
       
      Err.Clear
     
End Sub

Friend Sub HRG(fShowHourGlass As Boolean)

   If fShowHourGlass = True Then
      Screen.MousePointer = 11
   Else
      Screen.MousePointer = 0
   End If
   
End Sub
 
Private Sub Form_Unload(Cancel As Integer)
  Set frmFTP = Nothing
End Sub


   ' Here's the code for FTPMain.bas
   ' Remember to set your project start up to Sub Main()

      Public Sub Main()
            Load frmFTP
            frmFTP.Show
            frmFTP.FTPFile "my ip address", "PUT", "myuser",
                         "mypwd", "C:\temp\test.txt", "test.txt"
            frmFTP.FTPFile "my ip address", "GET", "myuser",
                        "mypwd", "test.txt", "c:\temp\test2.txt"
            Unload frmFTP
       End Sub

Open in new window

0
 
LVL 10

Expert Comment

by:cool12399
ID: 35095598
pps, please accept this question now, because that answers/helps. thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now