FTP a file in form load event

In my form load event, I want to FTP a file from my PC to a Unix box.
Can anybody help with the command or sample code on how I could
do this?

Thanks.
mjcotterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vbWayneCommented:
'transfer to ftp site
'I haven't used this..found it on the
'net an kept it for future use
'perhaps it will help

Option Explicit

Type Com
    BackCode As String
    Command As String
    Reply As String
    BackCommand As String
End Type

'''''''''''''''''''''''''''''''''''''''

'<<<<<<<<<<<<<  form code >>>>>>>>>>>>>>>>>

Option Explicit

Dim Commun(5) As Com
Dim CommunState As Integer
Dim Site As String
Dim Username As String
Dim Password As String
Dim Remotefile As String
Dim Localfile As String
Dim Buffersize As Long
Dim CloseAfterSend As Boolean

Private Sub Command1_Click()

    Site = "ftp.iprimus.ca"
    Username = "whoever"
    Password = "whateverworks"
    Localfile = "c:\my documents\fix.txt"
    Remotefile = "public_html/fix.txt"
    Commun(0).Reply = "220"
    Commun(0).BackCommand = "USER " + Username
    Commun(1).Reply = "331"
    Commun(1).BackCommand = "PASS " + Password
    Commun(2).Reply = "230"
    Commun(2).BackCommand = "TYPE I"
    Commun(3).Reply = "200"
    Commun(3).BackCommand = "PORT"
    Commun(4).Reply = "200"
    Commun(4).BackCommand = "STOR " + Remotefile
    Commun(5).Reply = ""
    Commun(5).BackCommand = ""
    Buffersize = 2920
    Dim Nr1 As Integer
    Dim Nr2 As Integer
    Dim LocalIP As String
    LocalIP = Winsock1.LocalIP
   

    Do Until InStr(LocalIP, ".") = 0
        LocalIP = Left(LocalIP, InStr(LocalIP, ".") - 1) + "," + Right(LocalIP, Len(LocalIP) - InStr(LocalIP, "."))
    Loop

    Randomize Timer
    Nr1 = Int(Rnd * 12) + 5
    Nr2 = Int(Rnd * 254) + 1
    Commun(3).BackCommand = "PORT " + LocalIP + "," + Trim(Str(Nr1)) + "," + Trim(Str(Nr2))
    Winsock2.Close


    Do Until Winsock2.State = 0


        DoEvents
        Loop

        Winsock2.LocalPort = (Nr1 * 256) + Nr2
        Winsock2.Listen
        Winsock1.Close


        Do Until Winsock1.State = 0


            DoEvents
            Loop

            Winsock1.RemoteHost = Site
            Winsock1.RemotePort = 21
            Winsock1.Connect
            CommunState = 0


            Do Until Winsock1.State = 7 Or Winsock1.State = 9


                DoEvents
                Loop



                Select Case Winsock1.State
                    Case 9
                    MsgBox "Couldn't reach server " + Site + ".", vbOKOnly + vbInformation, "FTP Upper"
                    Case 7
                    Open Localfile For Binary As #1
                End Select

        End Sub



Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

    Dim tmpS As String
    Winsock1.GetData tmpS, , bytesTotal
    Debug.Print tmpS;


    Select Case Left(tmpS, 3)
        Case Commun(CommunState).Reply
        Winsock1.SendData Commun(CommunState).BackCommand + Chr(13) + Chr(10)
        Debug.Print Commun(CommunState).BackCommand
        CommunState = CommunState + 1
        Case "150"


        Do Until Winsock2.State = 7


            DoEvents
            Loop

            SendNextData
            Case "226"
            Winsock1.Close


            Do Until Winsock1.State = 0


                DoEvents
                Loop

                MsgBox "Transfer complete.", vbOKOnly + vbInformation, "FTP Upper"
                Case Else
                MsgBox "Bad reply: " + Left(tmpS, Len(tmpS) - 2), vbOKOnly + vbInformation, "FTP Upper"
            End Select

    End Sub



Private Sub Winsock2_ConnectionRequest(ByVal requestID As Long)

    Winsock2.Close


    Do Until Winsock2.State = 0


        DoEvents
        Loop

        Winsock2.Accept requestID


        Do Until Winsock2.State = 7


            DoEvents
            Loop

        End Sub



Sub SendNextData()

    Dim Take As Long
    Dim Buffer As String
    If LOF(1) - Seek(1) < Buffersize Then Take = LOF(1) - Seek(1) + 1 Else Take = Buffersize
    Buffer = Input(Take, 1)
    Winsock2.SendData Buffer


    If Take < Buffersize Then
        Close #1
        CloseAfterSend = True
    End If

    On Error Resume Next
    Label1 = Trim(Str(Seek(1))) + "/" + Trim(Str(LOF(1)))
    On Error GoTo 0
End Sub



Private Sub Winsock2_SendComplete()



    If CloseAfterSend = True Then
        Winsock2.Close


        Do Until Winsock2.State = 0


            DoEvents
            Loop

            CloseAfterSend = False
        Else
            SendNextData
        End If

    End Sub


0
SpriCommented:
With FTP
  .URL = "FTP://" & txtServer.Text
  .UserName = txtUserName.Text
  .Password = txtPassword.Text
  .Execute , "CD " & txtLocation.text
   Do While .StillExecuting = True
       DoEvents
   Loop
  .Execute , "SEND " & txtFilename & " " & txtFilename
    Do While .StillExecuting = True              
  DoEvents
 Loop
  .Execute , "CLOSE"
  Do While .StillExecuting
            DoEvents
        Loop
    End With

The FTP object I refer to is the Inet Control.  txtServerName is the name like 'www.experts-exchange.com'
txtLocation.text is the location i am going to store the file.
So if i connected to a site and it brought me to /home/spri and i wanted my file to be in /home/spri/www
i would put 'www' here.
The Inet send command takes the local file name(including location) and also takes the remote file name(w/o location)
Hope this helps and the code doesn't get too mangled at posting.
Let me know if you need further help.
Spri.

0
lenlutzCommented:
'simple_ftp
' a form with nothing but internet transfer control on it
Option Explicit
'THIS WORKS GREAT
Private Sub Form_Load()
    With Inet1
        .Cancel
        .Protocol = icFTP
        .RemoteHost = "your.machine.tcpip.address"
        .UserName = "YOURNAME"
        .Password = "YOURPASS"
    End With

Inet1.Execute , "PUT c:\myfile.txt /tmp/myfile.txt"

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mjcotterAuthor Commented:
Worked like a charm!  Thank you.
Very nice and compact piece of code.
Exactly what I was looking for.
Thanks again!

Matt
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.