Page 2 of 2 FirstFirst 12
Results 41 to 54 of 54

Thread: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?

  1. #41
    New Member
    Join Date
    Apr 2007
    Posts
    4

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?

    Quote Originally Posted by jcis
    The info about the Download/Upload progress is raised to the Form where CFtp is declared, you can get the progress in this Form event:
    Code:
    Private Sub oFTP_TransferProgress(ByVal nPercent As Long, _
        ByVal fBytesReceived As Double, ByVal fFileSize As Double)
        
        'You can use this event to update a progress bar or
        'to give some other feedback to the user about the
        'download/upload progress.
        
        Me.ProgressBar1.Value = nPercent
        DoEvents
    End Sub
    Exactly. But yoy don't understand me.
    The var nPercent is not avaible, becuase fFileSize is zero.
    The problem is in (DownloadFile method) :
    Me.Files collection has zero elements.

    Code:
    For Each f In Me.Files
    If f.FileName = RemoteFile Then
    fFileSize = f.FileSize
    Exit For
    End If
    Next

  2. #42
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?

    I'm not sure I understand you... Do you want to download a file that is zero bytes in length? Since it doesn't take any time to download such a file, since there is nothing to download there is no reason to display any progress bar. Or do you mean that the class is raising an error? In that case you probably need to change your error trapping settings, click Tools > Options and on the General tab select "Break on unhandled errors" instead of the setting "Break in class module" which I then assume you have.

  3. #43
    New Member
    Join Date
    Apr 2007
    Posts
    4

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?

    Quote Originally Posted by Joacim Andersson
    I'm not sure I understand you... Do you want to download a file that is zero bytes in length? Since it doesn't take any time to download such a file, since there is nothing to download there is no reason to display any progress bar. Or do you mean that the class is raising an error? In that case you probably need to change your error trapping settings, click Tools > Options and on the General tab select "Break on unhandled errors" instead of the setting "Break in class module" which I then assume you have.
    If you try to download a file (not zero bytes) with DownloadFiles method the nPercent in this event ->

    Code:
     Private Sub oFTP_TransferProgress(ByVal nPercent As Long, _
        ByVal fBytesReceived As Double, ByVal fFileSize As Double)
    is always zero.
    The file is downloaded correctly.

  4. #44
    New Member
    Join Date
    Sep 2010
    Posts
    3

    Re: Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?

    Quote Originally Posted by Joacim Andersson View Post
    The attached ZIP file contains a bunch of classes I wrote a few years back that you can use for FTP. Even though it contains 5 classes and one module and you'll have to add them all to your project, you only create one object (an instance of CFtp). Here's how to use it (please read the comments below):
    VB Code:
    1. Private [b]WithEvents [/b]oFTP As CFtp
    2.  
    3. Private Sub Form_Load()
    4.     Set oFTP = New CFtp
    5.     'All arguments to the Connect method is optional
    6.     'you can set them via properties instead
    7.     oFTP.Connect "ftp.mysite.com", "username", "password"
    8.     ' Set the TransferType property to determent how a file
    9.     ' is transfered as ASCII (converts newlines) or as Binary
    10.     oFTP.TransferType = FTP_TRANSFER_TYPE_ASCII 'or FTP_TRANSFER_TYPE_BINARY
    11.     ' The UploadFile raises events while uploading
    12.     ' but the call will still not return until its done.
    13.     ' You can however cancel the transfer in the TransferProgress
    14.     ' event if you like by setting the CancelProperty to True
    15.     oFTP.UploadFile "c:\myfile.txt", "newfile.txt"
    16.     ' You can also use the PutFile method to upload a file,
    17.     ' however this method does not raise any events and does not
    18.     ' give you the option to cancel the transfer:
    19.     'oFTP.PutFile "c:\LocalFile.txt", "RemoteName.txt"
    20.    
    21.     ' To download a file simply use the DownloadFile method
    22.     ' if you want the events to fire or the GetFile method if
    23.     ' you are not interested in the progress.
    24.     '
    25.     ' The following shows how you can list the files in the current
    26.     ' remote directory into a listbox.
    27.     Dim oFile As CFtpFile
    28.     ' First argument:  File pattern (use * instead of *.* on Unix/Linux)
    29.     ' Second argument: (Optional) NoCache
    30.     oFTP.ListDir "*", True '<- Second argument (optional): NoCache
    31.     For Each oFile In oFTP.Files
    32.         If oFile.IsDirectory Then
    33.             List1.AddItem "[" & oFile.FileName & "]"
    34.         Else
    35.             List1.AddItem oFile.FileName
    36.         End If
    37.     Next
    38.     ' The CFtp class has a bunch of other method and properties such as
    39.     ' MakeDir, ChangeDir, DeleteDir, DeleteFile, FileExist, GetCurrDir
    40.     ' .. and so on
    41. End Sub
    42.  
    43. Private Sub oFTP_ErrorMsg(ByVal sErr As String)
    44.     'Error messages
    45.     Debug.Print "Error: " & sErr
    46. End Sub
    47.  
    48. Private Sub oFTP_StatusMsg(ByVal Msg As String)
    49.     'different status messages
    50.     Debug.Print Msg
    51. End Sub
    52.  
    53. Private Sub oFTP_TransferCompleted()
    54.     'a download/upload is completed
    55. End Sub
    56.  
    57. Private Sub oFTP_TransferProgress(ByVal nPercent As Long, _
    58.  ByVal fBytesReceived As Double, ByVal fFileSize As Double)
    59.     'You can use this event to update a progress bar or
    60.     'to give some other feedback to the user about the
    61.     'download/upload progress.
    62. End Sub
    Does this code works with multiple file uploads
    like i want to give it foldername and it automatically upload all files from it in ftp.
    Please Reply me as soon as possible.

  5. #45
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    The code does not include any UploadFolder or anything like that but you can easily write one yourself by looping through the files in a folder and call the UploadFile or the PutFile method for each file.

  6. #46
    New Member
    Join Date
    Sep 2010
    Posts
    3

    Smile Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    there is some problem when i am running your code
    line number 35. List1.AddItem oFile.FileName this one
    error is comming: Runtime error '424' Object Required
    but oFile.FileName contain some value like ".InstallerDB.swo"
    what is that?
    Could you help me out with these type of error.

    And Thanks for replying.

  7. #47
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    .InstallerDB.swo must be the file name of a file or directory on the FTP server. Object required is possibly on the List1, do you have a listbox named List1 on your form?

    You have the full source code of the classes so read the source to find out how they work. It's been over 9 years since I wrote this code so don't expect me to remember everything about it.

  8. #48
    New Member
    Join Date
    Sep 2010
    Posts
    3

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    Quote Originally Posted by Joacim Andersson View Post
    Create your own boolean variable, for example blnFTPExecuting, and set it to True when you start an upload or download. Then reset it to False in the TransferCompleted event.... Or, if you're not interested in the events use the PutFile function instead, that will not return until the file is uploaded, but you can of course in that case not show any progress either.



    Hi! Joacom Andersson
    This code will work until the upload not complete.
    means the boolean variable true work in the broken connection also and try to connection the ftp. because i something want like if there is some problem in ftp connection it(code) will work to until file is upload or it's give error.
    error in connection.

  9. #49
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    You handle errors in the Error event.

  10. #50
    New Member
    Join Date
    Nov 2010
    Posts
    2

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    Hello Joacim, thanks for sharing this FTP script, i used it in my little project , at the beginning it was working verywell, but when i try to upload a big file like 6mb or 4mb, it s crashing the application and not responding any more, and then I'm going to have to kill the proccess.

    Is there a solution to get over this problem, for these big files like 6mb?

    Thank you.

  11. #51
    New Member
    Join Date
    Nov 2010
    Posts
    2

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    I forgat to tell when its crashing. Its crashing at the end of the upload (&#37;100) on this big files like 4mb/6mb..

  12. #52
    New Member
    Join Date
    Sep 2011
    Posts
    5

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    Hi,

    I like your code, it works very well. I tried it in for the Upload function, works perfectly with the progress bar too.
    But when I try to download a file, the progress bar doesn't show progress.
    How can I fix this plz?

    Thank you in advance

  13. #53

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    You should not reply to old threads.
    The chance of being answered is nearly none. Maybe you should pm Joacim Andersson..
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  14. #54
    Registered User
    Join Date
    Jul 2016
    Posts
    1

    Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke

    Quote Originally Posted by moskyow View Post
    If you try to download a file (not zero bytes) with DownloadFiles method the nPercent in this event ->

    Code:
     Private Sub oFTP_TransferProgress(ByVal nPercent As Long, _
        ByVal fBytesReceived As Double, ByVal fFileSize As Double)
    is always zero.
    The file is downloaded correctly.
    Hi, I have facing the same problem, have you solved this issue?

Page 2 of 2 FirstFirst 12

Posting Permissions

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



Click Here to Expand Forum to Full Width