|
-
Apr 23rd, 2007, 10:30 AM
#41
New Member
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
 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
-
Apr 23rd, 2007, 11:02 AM
#42
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.
-
Apr 23rd, 2007, 11:39 AM
#43
New Member
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
 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.
-
Sep 30th, 2010, 05:15 AM
#44
New Member
Re: Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
 Originally Posted by Joacim Andersson
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:
Private [b]WithEvents [/b]oFTP As CFtp
Private Sub Form_Load()
Set oFTP = New CFtp
'All arguments to the Connect method is optional
'you can set them via properties instead
oFTP.Connect "ftp.mysite.com", "username", "password"
' Set the TransferType property to determent how a file
' is transfered as ASCII (converts newlines) or as Binary
oFTP.TransferType = FTP_TRANSFER_TYPE_ASCII 'or FTP_TRANSFER_TYPE_BINARY
' The UploadFile raises events while uploading
' but the call will still not return until its done.
' You can however cancel the transfer in the TransferProgress
' event if you like by setting the CancelProperty to True
oFTP.UploadFile "c:\myfile.txt", "newfile.txt"
' You can also use the PutFile method to upload a file,
' however this method does not raise any events and does not
' give you the option to cancel the transfer:
'oFTP.PutFile "c:\LocalFile.txt", "RemoteName.txt"
' To download a file simply use the DownloadFile method
' if you want the events to fire or the GetFile method if
' you are not interested in the progress.
'
' The following shows how you can list the files in the current
' remote directory into a listbox.
Dim oFile As CFtpFile
' First argument: File pattern (use * instead of *.* on Unix/Linux)
' Second argument: (Optional) NoCache
oFTP.ListDir "*", True '<- Second argument (optional): NoCache
For Each oFile In oFTP.Files
If oFile.IsDirectory Then
List1.AddItem "[" & oFile.FileName & "]"
Else
List1.AddItem oFile.FileName
End If
Next
' The CFtp class has a bunch of other method and properties such as
' MakeDir, ChangeDir, DeleteDir, DeleteFile, FileExist, GetCurrDir
' .. and so on
End Sub
Private Sub oFTP_ErrorMsg(ByVal sErr As String)
'Error messages
Debug.Print "Error: " & sErr
End Sub
Private Sub oFTP_StatusMsg(ByVal Msg As String)
'different status messages
Debug.Print Msg
End Sub
Private Sub oFTP_TransferCompleted()
'a download/upload is completed
End Sub
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.
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.
-
Sep 30th, 2010, 06:09 AM
#45
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.
-
Sep 30th, 2010, 06:28 AM
#46
New Member
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.
-
Sep 30th, 2010, 06:40 AM
#47
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.
-
Oct 1st, 2010, 12:37 AM
#48
New Member
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke
 Originally Posted by Joacim Andersson
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.
-
Oct 1st, 2010, 04:14 AM
#49
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke
You handle errors in the Error event.
-
Nov 4th, 2010, 01:27 PM
#50
New Member
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.
-
Nov 4th, 2010, 01:33 PM
#51
New Member
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 (%100) on this big files like 4mb/6mb..
-
Sep 16th, 2011, 12:24 PM
#52
New Member
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
-
Oct 8th, 2011, 03:36 AM
#53
Thread Starter
Fanatic Member
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..
-
Jul 14th, 2016, 12:35 PM
#54
Registered User
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocke
 Originally Posted by moskyow
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|