| Dart Home | PowerTCP FTP for ActiveX | Custom Development | Reply | PowerTCP FTP for ActiveX Topics | Forums |
| Author | Forum: PowerTCP FTP for ActiveX Topic: FTP Retrieve to buffer() got nothing, help |
| chihchang From: wa, CA Vatican City State Posts: 14 Member Since: 12/05/03 |
posted December 10, 2003 3:28 AM here is my part of code: ============================ Dim buffer1() As Byte sub main() Open temp_name For Binary Access Write Shared As #1 Ftp1.Type = ftpImage Ftp1.TimeOut = 0 Ftp1.Login server, username, pass, , port end sub Private Sub Ftp1_Progress(ByVal FtpCmd As D...) If Status = ftpOk Then Select Case FtpCmd Case ftpPassword Ftp1.Retrieve download_file_name, buffer1(), 0 ElseIf Status = ftpInProgress Then Select Case FtpCmd Case ftpRetrieve Label1.Caption = buffer1() Put #1, , buffer1() ========================================= I got nothing in buffer1(), why? |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 10, 2003 8:51 AM You have timeout set to 0 so the Login method is asynchronous. What's happening is your program is exiting before the connection has even been established. Try setting timeout to 30000 and see what happens. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 10, 2003 9:02 AM Actually on further examination, I don't even see how this code could ever work. How are you creating events in a VB module? |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 10, 2003 9:34 AM I rewrote your code so that it ran and I think I am now doing what you were intending to show me. It looks like there is a problem with trying to retrieve to a string or byte array using async mode. I have written this up as issue #2226. Please contact our support department via email or phone for info on resolution. If you don't want to wait for the problem to be corrected, you have two workarounds: 1) Switch to blocking mode 2) Retrieve to a file instead of a string or byte array |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 10, 2003 9:50 AM While writing up the issue and double checking your code, I found that there is no bug. The problem is in your code. You are expecting the file to be complete when the progress event fires with ftpInProgress. That will not be the case. You should be checking for a status of ftpOk. If you do that, then the buffer will contain the data you want. |
| chihchang From: wa, CA Vatican City State Posts: 14 Member Since: 12/05/03 |
posted December 10, 2003 8:34 PM > You should be checking for a status of ftpOk. If you do that, then the buffer will contain the data you want. How to code that? > 1) Switch to blocking mode > 2) Retrieve to a file instead of a string or byte array. It works, but it's not what I want. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 10, 2003 9:55 PM Move the code that you have in the Status = ftpInProgress section to the Status = ftpOk section. |
| chihchang From: wa, CA Vatican City State Posts: 14 Member Since: 12/05/03 |
posted December 11, 2003 3:58 AM It doesn't work. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 11, 2003 8:41 AM How is this app written? Is Sub Main part of a module? If so, how did you add the events? Are the events even firing? |
| chihchang From: wa, CA Vatican City State Posts: 14 Member Since: 12/05/03 |
posted December 11, 2003 10:54 AM The code is in form not module, and events fired also. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 11, 2003 11:16 AM If it's in a module, then why do you have a Sub Main()? |
| chihchang From: wa, CA Vatican City State Posts: 14 Member Since: 12/05/03 |
posted December 11, 2003 8:32 PM I post the wrong code, sorry. The correct code is: =========================================== Dim buffer1() As Byte sub start_download(server As String, username As String, pass As String, port As Long, download_filename As String, des_filename As String) Open des_filename For Binary Access Write Shared As #1 Ftp1.Type = ftpImage Ftp1.TimeOut = 0 Ftp1.Login server, username, pass, , port end sub Private Sub Ftp1_Progress(ByVal FtpCmd As DartFtpCtl.CommandConstants, ByVal Status As DartFtpCtl.StatusConstants, ByVal Reply As String, ByVal Count As Long, ByVal Size As Long) If Status = ftpOk Then Select Case FtpCmd Case ftpPassword Ftp1.Retrieve download_file_name, buffer1(), 0 Case ftpRetrieve Ftp1.Logout Label2.Caption = "Ftp Transfer is complete. " & transfer End Select ElseIf Status = ftpInProgress Then Select Case FtpCmd Case ftpRetrieve Form2.Label1.Caption = buffer1() Put #1, , buffer1() Label1.Caption = Count & "/" & Size & " done." Case ftpSize file_size = Replace(Reply, "213 ", "") Label9.Caption = "File Size: " & file_size End Select End If Exit Sub onerror: ' Any error jumps here Debug.Print "Error #" + CStr(Err.Number) + ": " + Err.Description End Sub ==================================== I got the Count and size. But buffer1() got nothing. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 11, 2003 9:13 PM You are still trying to access the buffer before the transfer is complete. You can't do that. This code will work: Private Sub Ftp1_Progress(ByVal FtpCmd As DartFtpCtl.CommandConstants, ByVal Status As DartFtpCtl.StatusConstants, ByVal Reply As String, ByVal Count As Long, ByVal Size As Long) If Status = ftpOk Then Select Case FtpCmd Case ftpPassword Ftp1.Retrieve download_file_name, buffer1(), 0 Case ftpRetrieve Form2.Label1.Caption = buffer1() Put #1, , buffer1() Label1.Caption = Count & "/" & Size & " done." Label2.Caption = "Ftp Transfer is complete. " & transfer Ftp1.Logout End Select ElseIf Status = ftpInProgress Then If FtpCmd = ftpSize Then file_size = Replace(Reply, "213 ", "") Label9.Caption = "File Size: " & file_size End If End If Exit Sub onerror: ' Any error jumps here Debug.Print "Error #" + CStr(Err.Number) + ": " + Err.Description End Sub |
| chihchang From: wa, CA Vatican City State Posts: 14 Member Since: 12/05/03 |
posted December 11, 2003 9:24 PM If I put in Status = ftpOk, then all data are retrieve in buffer after download complete. right? That will be a problem if I download a 100M bytes file. Is all 100M bytes data save in memory? What I trying to do is retrieve 4k, and write to disk, and Retrieve and write. Not save in memory but disk file. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 11, 2003 9:29 PM If you are retrieving a file that large, then you shouldn't be using a Byte array. Why don't you just retrieve to a file? |
| chihchang From: wa, CA Vatican City State Posts: 14 Member Since: 12/05/03 |
posted December 11, 2003 10:27 PM I wanna try multi-part download. Like flashget. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted December 11, 2003 10:51 PM I still don't see why you need to use bytes. Can't you just retrieve to files and then put them back together later? |
| chihchang From: wa, CA Vatican City State Posts: 14 Member Since: 12/05/03 |
posted June 19, 2004 6:14 AM > Can't you just retrieve to files and then put them back together later? It'll happen File/IO errors sometimes. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted June 21, 2004 9:26 AM I'm sorry, but I don't think I am going to be able to help with something this specific on the forum. Please report the problem to support@dart.com. Make sure you include your serial number in the email. |
| Reply | PowerTCP FTP for ActiveX Topics | Forums |
This site is powered by
PowerTCP WebServer for ActiveX
|