Re: Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
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):
Re: Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
No, it will not timeout by itself, however the server might close an inactive connection after X number of minutes. However you should do it by calling the CloseConnection method.
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
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.
Last edited by Joacim Andersson; Apr 15th, 2006 at 07:19 AM.
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
Public Function Connect(Optional RemoteHost As String, Optional UserName As String, Optional Password As String, Optional nPort As String, Optional ProxyName As String) As Boolean
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
Alright, now I'm having a little bit of trouble with the send file.. I'm running a personal ftp client and I'm allowing people to send files to me. I see myself connect, but it disconnects very fast and doesn't send the file. Here's my code. Thanks for the help.
File = Format(Date, "mm.dd.yy") & " ~ " & Format(Time, "hh.mm.ss")
Set oFTP = New CFtp
oFTP.Connect "mrtikki2.no-ip.org", "Username", "Password", "2121"
oFTP.TransferType = FTP_TRANSFER_TYPE_BINARY
oFTP.UploadFile "c:\" & File & ".txt", File & ".txt"
End Sub
Private Sub oFTP_TransferCompleted()
'oFTP.CloseConnection
'Unload Form1
End Sub
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
The CFtp class doesn't disconnect from the server unless you call the CloseConnection method, so it must be your FTP server that closes the connection.
EDIT#2:: I had my friend connect to my ftp server using flashfxp with the same user and pass, and they could upload fine.. So I do not believe it is a problem with my server.
EDIT#3:: I was wondering, does this use passive or no?
Last edited by SC I VeNoM I; Apr 17th, 2006 at 06:25 PM.
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
Originally Posted by SC I VeNoM I
Would it be hard to put passive connections in this?
Yes, pretty hard... What you need to do is to set the PassiveSementic property of the CFtp class to True... Oh yeah, on second thought that wasn't very hard
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
Lol, sorry, but how would I do this? This is what I've tried
Public Function Connect(Optional RemoteHost As String, Optional UserName As String, Optional Password As String, Optional nPort As String, Optional PassiveSementic As Boolean, Optional ProxyName As String) As Boolean
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
Joacim Andersson, did you notice any problem while connecting to some ftps?
It worked great inside the network, but for outside ftps it didn't work always.
Any clue why would this happen?
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
I've never had any problems connecting to any FTP server, unless of course the server uses SFTP which is a whole other thing. If you have problems you should check your firewall settings.
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
Hi Joacim, Im using the classes you attached here.
I'm trying to create an app that will update the FTP files according to local files (it makes a backup of a folder content), but it should just upload files when they are new. I thought about using the file date, if its newer than the file in the FTP it should upload, else not. But: FTP files always have the date when they were uploaded, not modified, so this logic is not valid.
Then the question: How would you know when the file is exactly the same so it shouldn't be uploaded again?
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
Well, checking the dates should still work. If a local file is newer than the file on the server it must have been changed since it was last uploaded. You could also keep a log file that stores the date/time of the local file before it uploads it and simply compare the log entry against the current date/time of the local file. If it's newer it should be uploaded again.
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
Dear Joacim Andersson,
The internal error occured when transmit the filename called(C:\PruCallListStatus_ByCSR_2006-12-27.csv.pgp). How can I resolve it using your lib? Could you tell me?
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
nPercent is one of the arguments passed to the event:
Private Sub oFTP_TransferProgress(ByVal nPercent As Long, _
ByVal fBytesReceived As Double, ByVal fFileSize As Double)
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
I understand that, but I want to know how to calculate that nPercent so that when I use it in the progress bar, the progress bar would actually show the correct progress of the file being uploaded.
Re: [RESOLVED] Possible to download/upload files into FTP using WinSock 2.0 or CSocket ?
Originally Posted by moskyow
Ok, but the informarmation about the download progress is not avaible.
This is the problem.
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