Link to home
Start Free TrialLog in
Avatar of cantrell
cantrell

asked on

FTP a file

I need to know how to FTP a text file up to a server and append to one that's already there. I would prefer to use the 'inet' control if at all possible, since I already have that one in my project.
Avatar of VBGuru
VBGuru
Flag of India image

Using the State Event with the GetChunk Method
When you are downloading data from a remote computer, an asynchronous connection will be made. For example, using the Execute method with the operation "GET", will cause the server to retrieve the requested file. When the entire file has been retrieved, the State argument will return icResponseCompleted (12). At that point, you can use the GetChunk method to retrieve the data from the buffer. This is shown in the example below:
Private Sub Inet1_StateChanged(ByVal State As Integer)
      Dim vtData As Variant ' Data variable.
      Select Case State
      ' ... Other cases not shown.
      Case icResponseCompleted ' 12
            ' Open a file to write to.
            Open txtOperation For Binary Access _
            Write As #intFile

            ' Get the first chunk. NOTE: specify a Byte
            ' array (icByteArray) to retrieve a binary file.
            vtData = Inet1.GetChunk(1024, icString)

            Do While LenB(vtData) > 0
                  Put #intFile, , vtData
                  ' Get next chunk.
                  vtData = Inet1.GetChunk(1024, icString)
            Loop
            Put #intFile, , vtData
            Close #intFile
      End Select
End Sub
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cantrell
cantrell

ASKER

Good answer. However, you forgot to put the      
'WAIT UNTIL WE'RE FINISHED EXECUTING THE CD COMMAND.
        Do
          DoEvents
        Loop Until Not Inet1.StillExecuting

after the "Inet1.Execute , "CD incoming" 'Change remote dir to incoming" line, which you need. Otherwise, you'll get 'still executing last command' message when trying to do the upload.

thanks.
Oops! Sorry, I was just typing the code directly into EE and didn't actually run the code...


Thanks for the points! Glad I could help!


Cheers!
I also forgot this to end the FTP Session:

Inet1.Execute , "CLOSE"


Cheers!




Perfect. Thank you very much.