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.
LVL 2
cantrellAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mcriderConnect With a Mentor Commented:
This is how you use FTP with the INET control...  The following will send the file "c:\autoexec.bat" to the host "caas.com".  The remote file will be called "testfile" and will be put in the  directory called "incoming":

    Inet1.URL = "ftp://caas.com" 'CHANGE caas.com TO REMOTE HOSTNAME
    Inet1.Password = "noneofyourbusiness" 'Password to logon to remote
    Inet1.UserName = "mcrider" 'UserID to logon remote
    Inet1.Execute , "CD incoming" 'Change remote dir to incoming
    Inet1.Execute , "SEND c:/autoexec.bat testfile"


Unfortunately, the INET control does not support appending to files...  It will overwrite the file...



Cheers!
0
 
VBGuruCommented:
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
0
 
cantrellAuthor Commented:
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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mcriderCommented:
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!
0
 
mcriderCommented:
I also forgot this to end the FTP Session:

Inet1.Execute , "CLOSE"


Cheers!




0
 
cantrellAuthor Commented:
Perfect. Thank you very much.
0
All Courses

From novice to tech pro — start learning today.