Ftp Help Required App looks like its frozen
Hi guys i got the following code for ftp download problem i have is its like the app is frozen for the duration of the download i checked in task manager and pc also thinks its not repsponding this corrects when download finishes. its usually for a second or so on 3 mb files but the bigger the file the longer the freeze pc still works fine all the time this is happening its the app that is non reponsive. i dont understand this code as well as i could and i cant seem to fix it. any help would be great
VB Code:
Private Sub downloadFile_Click()
Dim i As Long
On Error Resume Next
For i = 0 To List2.ListCount - 1
'Check if file has been selected
If List2.Selected(i) = True Then
Call FtpGetFile(hConnection, sFile.Text, App.Path & "\" & sFile.Text, 0, 0, 2, 0)
DoEvents
End If
Next
End Sub
Sub DownloadFiles(ftp_url As String, username As String, password As String)
Dim sOrgPath As String
'open an internet connection
hOpen = InternetOpen("API-Guide sample program", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
'connect to the FTP server
hConnection = InternetConnect(hOpen, ftp_url, INTERNET_DEFAULT_FTP_PORT, username, password, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
sOrgPath = String(MAX_PATH, 0) 'create a buffer to store the original directory
FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath) 'get the directory
FtpSetCurrentDirectory hConnection, "/jd/logs/" 'set the current directory to 'root/httpdocs'
EnumFiles hConnection 'enumerate the file list from the current directory ('root/testing')
End Sub
Private Sub ftpconnect_Click()
If ftpconnect.Caption = "Connect" Then
Screen.MousePointer = vbHourglass
DownloadFiles txtFTP, txtUserName, txtPassword
Screen.MousePointer = vbDefault
ftpconnect.Caption = "Disconnect"
Else
If ftpconnect.Caption = "Disconnect" Then
InternetCloseHandle hConnection
InternetCloseHandle hOpen
List2.Clear
ftpconnect.Caption = "Connect"
End If
End If
End Sub
thanks in advance
Re: Ftp Help Required App looks like its frozen
Hi guys also in looking at this code how could it be moded to resume a dl rather than dl complete file? thanks again
Re: Ftp Help Required App looks like its frozen
an Application Freeze usually happens when it encounters a line of code that takes much time for execution. There are various ways of getting rid of this. Try to check the codebank for some sources.
Re: Ftp Help Required App looks like its frozen
Correct! Besides there could be a timed out or probably the size is big for downloading. Have you tried downloading text files only?
Re: Ftp Help Required App looks like its frozen
Re: Ftp Help Required App looks like its frozen
The Inet APIs (which I assume is what you're using) will appear to "freeze" your app when they're doing something, like downloading a file. I'm not aware of any way around this other than executing the functions in another thread.
This is why I personally use the Winsock control instead. But that will add another dependency to your project.
Re: Ftp Help Required App looks like its frozen
Thanks digi rev for the reply i wish i could change to that now but i didnt write this codes as i am fairly new to vb and i dont think i could mod it to use winsock instead