Results 1 to 13 of 13

Thread: FTP (VB6)

  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FTP (VB6)

    I would like to create a facility within my project, as maybe an addon or something of the sort to transfer files.

    Currently, through my application, I can E:Mail pdf and jpg files to anyone with E:Mail.

    I have been asked if it is possible to upload and download the files to a designated server / path instead.

    I think FTP may be the way to go here.
    I know nothing about FTP and wondered if anyone could enlighten me in this area.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FTP (VB6)

    You might use the Microsoft Internet Transfer Control (msinet.ocx in C:WindowsSystem32). See Using the Internet Transfer Control (technical stuff!)

    You can also search this forum for ftp, for example see <post#=266736>post 266736</post#>.

  3. #3
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: FTP (VB6)

    If the server/path is known then you could just use the FileCopy statement.

    e.g. FileCopy FromFile, ToFile

    Regards,
    Kevin Bell

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FTP (VB6)

    Thanks for the replies on this.

    I'm still trying to get my head around this at the moment.

    I've not had any dealings with FTP before so is difficult to understand.
    (What setup do I need, How do I setup a server, client etc etc)
    I downloaded an excellent demo from FreeVBcode.com which has an interesting project.

    I could do with an FTP address as an example so I can have a closer look at the code in the prject.
    Does anyone know of one ?

    Thanks again.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FTP (VB6)

    Many ISPs provide some web space with an Internet account. You might check if you or one of your co-workers has a personal web space; if so, you can use that to test uploading and downloading.

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FTP (VB6)

    Ok, I've now got the link setup and have started messing with code.
    Reading the Microsoft literature, I should be able to download a file programatically so just to test, the following code is supposed to do just that.
    It comes back "Still executing last request"

    Have I got the correct structure for the URL including the subfolders ?
    (I have replaced the IP with # symbols for site security)

    <pre>Private Sub Command2_Click()
    With Inet1
    .URL = "###.##.###.#mmpdfimage"
    .UserName = "MyUserName"
    .Password = "MyPassword"
    .Execute , "DIR"
    'MsgBox .URL
    .Execute , "GET 18172-01.jpg C:Temp18173-01.jpg"


    End With

    End Sub</pre>


  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FTP (VB6)

    I don't know anything about FTP, so I hope somebody else will chime in.

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FTP (VB6)

    Thanks Hans.

    There are some interesting articles on VBnet, I may gather a few idea's from there.

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FTP (VB6)

    I found this example using MSINET.OCX control.
    I think it is closer to what I need to achieve.

    <pre>Option Explicit

    Function UploadFile(ByVal HostName As String, _
    ByVal UserName As String, _
    ByVal PassWord As String, _
    ByVal LocalFileName As String, _
    ByVal RemoteFileName As String) As Boolean

    Dim FTP As Inet

    Set FTP = New Inet

    With FTP
    .Protocol = icFTP
    .RemoteHost = HostName
    .UserName = UserName
    .PassWord = PassWord
    .Execute .URL, "Put " + LocalFileName + "" + RemoteFileName
    Do While .StillExecuting
    DoEvents
    Loop
    UploadFile = (.ResponseCode = 0)
    End With
    Set FTP = Nothing
    End Function

    Private Sub Command1_Click()
    UploadFile "IP.12.345.678", "MyUserName", "MyPassWord", "L:MMPDFImage99999-91.jpg", "L:MMPDFImage99999-91.jpg"

    End Sub</pre>


    If this spurns anyone, It would help me a great deal.

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FTP (VB6)

    Ok, I have a solution for those who come across this situation in the future:
    This example will Send a file and recieve also. <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>

    Sub Main : Module :

    <pre>Public Sub Main()
    Load frmFTP
    frmFTP.Show
    frmFTP.FTPFile "IP#.##.###.###", "PUT", "UserName", "Password", _
    "L:MMPDFImage99999-88.jpg", "MMPDFImage99999-88.jpg"

    frmFTP.FTPFile "IP#.##.###.###", "GET", "UserName", "Password", _
    "MMPDFimage18173-02.jpg", "L:MMPDFImage18173-02.jpg"

    Unload frmFTP
    End Sub</pre>


    Form : Module :

    <pre>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://" & sFTPUser & ":" & sFTPPwd & "@" & sFTPServer

    Inet1.Protocol = icFTP
    Inet1.RequestTimeout = 60
    Inet1.RemotePort = 21
    Inet1.AccessType = icDirect
    Inet1.URL = sURL

    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
    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:" & Space(5) & msCurrentFile
    Case icDisconnecting: Me.lblRESPONSE.Caption = "Disconnecting..."
    Case icDisconnected: Me.lblRESPONSE.Caption = "Disconnected"
    Case icError: MsgBox "FTP 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</pre>


  11. #11
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FTP (VB6)

    Extremely long piece of code (over 6,000 characters) moved to attachment by HansV

    With the attached form module. when closing the application, it seems the connection is still open in the background.
    I've tried "Quit" & "CLOSE" but may have it in the incorrect position within the module.

    Can anyone see where it's hanging ?
    This only happens once files have been uploaded using Inet1

  12. #12
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Marietta, Georgia, USA
    Posts
    296
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Re: FTP (VB6)

    Maybe you can try this when the application is shutting down (maybe in Form_Unload):

    if Inet1.StillExecuting then
    Inet1.Cancel
    end if
    Rick Groszkiewicz
    Life is too short to drink bad wine (or bad coffee!)

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FTP (VB6)

    Thanks for the advise Rick, unfortunately it doesn't work.

    I've checked the queryUnload for the project and tried to force a form name to see if it's still open. Its not.

    if Inet1.StillExecuting then
    msgbox "I'm Still Open"
    Inet1.Cancel
    end if

    Doesn't work.

    None of the forms are open, but the connection is, for about 5 seconds after the application is closed.
    So if I close the application after using FTP, it won't open for about 5 seconds.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •