DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: VB6 - FTP within Visual basic

  1. #1
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60

    VB6 - FTP within Visual basic



    Please, I need someone to show me the correct synatx - code to FTP a file (in an Access table) to a server.

    The access table contains the following information:
    Code:
    Open
    10.8.44.34
    Username
    Password
    File path - sourcefile destinationfile
    Quit.
    I tried to run the code below and I get: a "Runtime error 438 - Object does not support this property of method"

    Code:
    InetFTP.Execute "ftp://mfuchk:58UA?UUW@10.8.37.44", "Put \\Livctrls03-08\Data1\APP\UNCLAIMW\UCCTest\Databases\DataFiles\Emp_Messages.txt  W.APPHRMS.UCCHKMSG"

    I also trried the code below and got: a Runtime Error 13 - Type Mismatch.

    Code:
    InetFTP.ExecWB  "ftp://mfuchk:58UA?UUW@10.8.37.44", "Put \\Livctrls03-08\Data1\APP\UNCLAIMW\UCCTest\Databases\DataFiles\Emp_Messages.txt  W.APPHRMS.UCCHKMSG"
    What am I doing wrong? Maybe wrong FTP syntax?

    Thanks.
    giftx.

  2. #2
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263

  3. #3
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Also, if you don't want to use the INet control, try this

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    And another example.

  5. #5
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Nuts, i just realised my suggestion uses a 'Chillkat' control.
    Trial periods and whatever.

    So here's a better one...
    I couldn't find the link, so i attached it

    Feel free to uncomment bits you want, but what is there should be sufficent



    How to use:
    Code:
    Dim cFTP As clsFTP
    Dim bSuccess As Boolean
    Dim sError As String
    
    Set cFTP = New clsFTP
    
    With cFTP
        If .OpenConnection(ServerName, UName, Pass) Then
            
            'for downloading
            bSuccess = .FTPDownloadFile(LocalFile, RemoteFile)
            
            'If you are uploading
            'bSuccess = .FTPUploadFile(LocalFile, RemoteFile)
            
            If bSuccess = False Then
                sError = .SimpleLastErrorMessage
            Else
                sError = "Success!"
            End If
            
            .CloseConnection
        Else
            .CloseConnection
            sError = .SimpleLastErrorMessage
        End If
        
    End With
    
    
    MsgBox sError

    P.S. If anyone recognises this, or knows the link to it, could you tell me please?
    Attached Files Attached Files
    Last edited by CptNeutral; 07-16-2008 at 08:35 AM.

  6. #6
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60

    VB6 - FTP Within Visual Basic

    Hi CptNeutral.
    Thanks for your post. Please correct me if I'm wrong.

    I am assuming that I have to unzip the file: "ClsFTP.zip" and put it inside my VB module?

    Also, in the OpenConnection(ServerName, Uname, Pass),
    I do not have a servername. But I have an IP address - 10.2.34.8, username and password.

    What would the "LocalFile" and "RemoteFile" be?

    I am taking a txt file from this location:
    Code:
    "\\Livctrls03-08\Data1\APP\UNCLAIMW\UCCTest\Databases\DataFiles\Emp_Messages.txt", True)
    and sending it to the remote server with the IP address I specified above.

    your response will be greatly appreciated.
    Giftx.

  7. #7
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60
    I copied clsFTP.zip code and pasted it inside my vb module. On compile, I these line declaration lines where hilited in red, with the error message: "Only valid in object module".

    Code:
    Public Event FileTransferProgress(lCurrentBytes As Long, lTotalBytes As Long)
    
    RaiseEvent FileTransferProgress(Sum, Size)
    Also, this code within my source code is hilited in red:
    Code:
    If .OpenConnection(10.8.37.44,mfuchk,58UA?UUW) Then
    Below is my source code as I set it up:

    Code:
    Dim cFTP As clsFTP
    Dim bSuccess As Boolean
    Dim sError As String
    
    Set cFTP = New clsFTP
        
        With cFTP
            If .OpenConnection(10.8.37.44,mfuchk,58UA?UUW)  Then  ==> this line is hilited in RED
                
                'Upload File:
                '------------
                bSuccess = .FTPUploadFile("\\Livctrls03-08\Data1\APP\UNCLAIMW\UCCTest\Databases\DataFiles\Emp_Messages.txt, W.APPHRMS.UCCHKMSG")
                
                'Download File:
                '--------------
                bSuccess = .FTPDownloadFile(LocalFile, RemoteFile)
                
                If bSuccess = False Then
                   sError = .SimpleLastErrorMessage
                Else
                   sError = "Success"
                End If
                
                  .CloseConnection
                Else
                  .CloseConnection
                   sError = .SimpleLastErrorMessage
            End If
        
        End With
        
        MsgBox sError
    Thanks.
    Giftx

  8. #8
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Quote Originally Posted by CptNeutral
    P.S. If anyone recognises this, or knows the link to it, could you tell me please?
    Yes it came from this example on FreeVBCode.com
    FTP Transfer Class, using wininet.dll

  9. #9
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Quote Originally Posted by Ron Weller
    Yes it came from this example on FreeVBCode.com
    FTP Transfer Class, using wininet.dll
    So it did. I just saw 'wininet' and thought it meant the Inet control.
    Tar muchly


    ----------------------------------------------------------------------


    GiftX, you need to put the code inside a class module (which is like an object - you load it into and out of memory using Set statements)


    I've altered your code, and hopefully it should work after you put the code from the zip file into a Class Module:


    Code:
    'In the declarations
    Private WithEvents cFTP As clsFTP
    
    
    'Procedure
    Private Sub Test()
    Dim bSuccess As Boolean
    Dim sError As String
    
    
    'This loads/initialises the FTP object
    Set cFTP = New clsFTP
    
    
    
    If cFTP.OpenConnection("10.8.37.44", "mfuchk", "58UA?UUW") Then
        
        bSuccess = cFTP.FTPUploadFile("\\Livctrls03-08\Data1\APP\UNCLAIMW\UCCTest\Databases\DataFiles\Emp_Messages.txt", "W.APPHRMS.UCCHKMSG")
        
        If bSuccess Then
            sError = "Success"
        Else
            sError = cFTP.SimpleLastErrorMessage
        End If
        
        cFTP.CloseConnection
    End If
    
    MsgBox sError
    
    
    
    'unload/terminate the ftp object
    Set cFTP = Nothing
    End Sub
    The reason you were getting "Only Valid in Object Module" is because the Event code needs to be for an object. Think of cFTP as a textbox, for example. When someone types in the textbox, the textbox raises and event (e.g. Text1_Change) so you can respond to it.

    The WithEvents bit in "Private WithEvents cFTP As clsFTP" makes VB understand that the cFTP object can raise an event, and your form will intercept it, like this:

    Code:
    Private Sub cFTP_FileTransferProgress(lCurrentBytes As Long, lTotalBytes As Long)
    Dim lPercent As Long
    
    lPercent = 100 * lCurrentBytes / lTotalBytes
    
    'you can now show this percentage using a progress bar, for example
    
    End Sub
    If you're still stuck, download the attachment
    Attached Files Attached Files
    Last edited by CptNeutral; 07-17-2008 at 07:57 AM.

  10. #10
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60

    VB6 - FTP Within Visual Basic - Module NOT working

    Thank you very much for your directives. I created a class1 module called "clsFTP.cls" and copied the clsFTP.zip source codes/declarations into the class module.

    I added
    Code:
    Private WithEvents cFTP As clsFTP
    to my declarations area.

    It does not seem to recongnize object "clsFTP" when I coded:
    Code:
    Set cFTP = New clsFTP
    When I ran the program, I got an error: User-defined type not defined on the code below:
    Code:
    Private mDirCol As New cDirList
    Also, you know when you type an object name followed by a period (.), it usually gives you a list of items to select from. but clsFTP and cFTP. does not list any items.

    Any help will be appreciated.
    You folks enjoy your weekend.
    Giftx.

  11. #11
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60

    VB6 - FTP Within Visual Basic - Module NOT Working.

    On another try, I downloaded your FTP.zip module and tried to compile/run it.

    I got another "compile error - Argument not optional"and it hilited this code:
    Code:
    .FTPUploadFile
    Thanks.

    Giftx.

  12. #12
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Have you tried running the code in the zip file by itself?
    It should work without any errors

    If you want, you could post your code, and i'll point out where you're going wrong

    Sorry about the late reply

  13. #13
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60
    Good morning CptNeutral.
    sorry for the late response. Yes, I ran the code in the zip file by itself and got an error on this line:
    Code:
    bSuccess = cFTP.FTPUploadFile("\\Livctrls03-08\Data1\APP\UNCLAIMW\UCCTest\Databases\DataFiles\Emp_Messages.txt")
    It hilited this particular code:
    Code:
    .FTPUploadFile
    Also, below is my own source code: I created a class module and called it: "clsFTP".
    Code:
    'Put FTP exection code here: Test Area#1
        '--------------------------------------
           Set cFTP = New clsFTP
        
           If cFTP.OpenConnection("10.8.37.44", "mfuchk", "58UA?UUW") Then
           
                'Upload File:
                '------------
                bSuccess = cFTP.FTPUploadFile("\\Livctrls03-08\Data1\APP\UNCLAIMW\UCCTest\Databases\DataFiles\Emp_Messages.txt")
        
                'Download File:
                '--------------
                'bSuccess = .FTPDownloadFile(LocalFile, RemoteFile)
        
                If bSuccess = False Then
                   sError = cFTP.SimpleLastErrorMessage
                Else
                   sError = "File Upload Successful"
                End If
        
                   cFTP.CloseConnection
            End If
       
            MsgBox sError
    Thanks.
    Giftx.

  14. #14
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60
    Sorry, I didn't include the error message:

    The Error message from your zip file code is "Argument not optional"

  15. #15
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Oh, you need to specify the remote file:

    Code:
    bSuccess = cFTP.FTPUploadFile("\\Livctrls03-08\Data1\APP\UNCLAIMW\UCCTest\Databases\DataFiles\Emp_Messages.txt", "Remote File Name.txt")

Similar Threads

  1. Replies: 0
    Last Post: 11-16-2005, 07:31 PM
  2. Replies: 0
    Last Post: 06-29-2005, 04:30 PM
  3. New Apress book by DevX section leader -- Bargain Error Price on BarnesAndNoble.com
    By Constance J. Petersen in forum dotnet.announcements
    Replies: 0
    Last Post: 07-26-2002, 03:32 PM
  4. New Site For Visual Basic Developers
    By Paul R. Wilde in forum vb.announcements
    Replies: 0
    Last Post: 08-13-2000, 08:35 PM
  5. Visual Basic Guru needed - Atlanta
    By Julie Sisson in forum vb.announcements
    Replies: 1
    Last Post: 04-06-2000, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center