-
Function works during step through but not on regular run
I'm using the Microsoft FTP examples to make a very basic upload/delete program for a FTP server (http://support.microsoft.com/default...b;en-us;832679). I upload files, get a file list, and delete files in the list that are selected. The problem is when I call the function GetFileList() it only returns the first file on the server. If I step through the same routine it returns all the files. What would cause this? I don't know why it would work by stepping through but not on a normal run.
-Allan.
-
Re: Function works during step through but not on regular run
And you don't get any errors? Start writting code to log out each steps into a log file so that you can track why it stops when in normal mode.
-
Re: Function works during step through but not on regular run
Quote:
Originally Posted by coolbiz
And you don't get any errors? Start writting code to log out each steps into a log file so that you can track why it stops when in normal mode.
No errors at all. The function is supposed to return a array of all files found on the server. When I step through it the array holds 15 items (the 15 files on the FTP server). When I do a normal run it returns only 1 item, the last file added to the server. I'm not that good at this stuff yet so I'll attempt to have it write to the debug thing each server response. Its just really odd it works during a step through.
-
Re: Function works during step through but not on regular run
It might be a problem w/ timing. During normal run, your code runs one after another and something might occur before something else and they are dependent on each other. So logging the steps (w/ datetime) will allow you to figure out what is going on.
-
Re: Function works during step through but not on regular run
O.k. I put in a bunch of Debug.writeline statements with time stamps and descriptions and also put some in at the begining of each sub thats being called. With the debug lines in the code I get the full file list about 50% of the time. If I comment them out or switched to release it goes back to just getting the first file. I think I've narrowed it down to a do while loop not waiting long enough for a server response...I'm just trying to figure out a way to put in a little delay to see if thats what it is.
-
Re: Function works during step through but not on regular run
system.threading.thread.currentthread.sleep() will pause the app.
-
Re: Function works during step through but not on regular run
Thanks a lot guys. It was in my Do While loop, it seems the program wasn't waiting long enough for the reply...or something. Heres the loop in question:
Code:
Do While (True)
m_aBuffer.Clear(m_aBuffer, 0, BLOCK_SIZE)
m_iBytes = m_objClientSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
' Delay here
System.Threading.Thread.CurrentThread.Sleep(10)
m_sMes += ASCII.GetString(m_aBuffer, 0, m_iBytes)
If (m_iBytes < m_aBuffer.Length) Then
Exit Do
End If
Loop
Its only a 10 ms delay but without it I don't get the full contents of the buffer. I ran it in both debug and release and with it in there it works everytime.
-Allan.
-
Re: Function works during step through but not on regular run
Quote:
Originally Posted by CrystalAnnoysMe
Its only a 10 ms delay but without it I don't get the full contents of the buffer. I ran it in both debug and release and with it in there it works everytime.
-Allan.
Just a update to throw another wrench in the works. I packaged my program into an installer and deplyed it to a couple PC's, including mine. Mine worked fine, another PC worked fine, a third PC gave me the single file again. I changed the delay to 100ms, redeployed to all three PC's and they all work. So this delay is almost PC specific. I'm thinking if 10ms worked on 2/3 that 100 should be fine on all but just in case I'm adding the ms timing into the settings so it can be changed on the fly just in case.
-Allan.
-
Re: Function works during step through but not on regular run
Which method is that code from? GetFileList() or ReadLine()?
-
Re: Function works during step through but not on regular run
Quote:
Originally Posted by coolbiz
Which method is that code from? GetFileList() or ReadLine()?
ReadLine(). Bad part is it now does a small delay on every line read from the FTP server so every response from login's, change directories, and whatnot had a tiny delay but on the same token every once in a while I was getting a crash on a logout/quit command and that has seemed to go away also. I have to assume its from the same issue, it wasn't getting a reply or reading the reply fast enough.
-Allan
Edit: and I added the delay into my programs options so it can be tweaked if needed, this way I can set mine back down to 10ms which I know works fine for my Pc and leave it higher for others.
-
Re: Function works during step through but not on regular run
But I thought you are working trying to get files list. GetFileList() does not use ReadLine() to enumerate the files right?
-
Re: Function works during step through but not on regular run
Quote:
Originally Posted by coolbiz
But I thought you are working trying to get files list. GetFileList() does not use ReadLine() to enumerate the files right?
The GetFileList function calls SendCommand(), which calls ReadReply(), which calls ReadLine() to get the response back from the FTP server. Every FTP command goes through the same process.
-
1 Attachment(s)
Re: Function works during step through but not on regular run
Try using this CLASS file.
-
Re: Function works during step through but not on regular run
Quote:
Originally Posted by coolbiz
Try using this CLASS file.
Quote:
Originally Posted by CrystalAnnoysMe
;)
-Allan
-
Re: Function works during step through but not on regular run
Did you try that CLASS? It is based on the Microsoft sample (modified a little to make it work w/ OPTION EXPLICIT and OPTION STRICT set to ON) and it works for me w/o putting any delay. I've tried to access my local FTP server and a public FTP server on the internet.
-
Re: Function works during step through but not on regular run
Quote:
Originally Posted by coolbiz
Did you try that CLASS? It is based on the Microsoft sample (modified a little to make it work w/ OPTION EXPLICIT and OPTION STRICT set to ON) and it works for me w/o putting any delay. I've tried to access my local FTP server and a public FTP server on the internet.
Yeah, that file looks pretty much identical to mine. I had a downloaded copy that I found on another site and it wasn't working so I then went to the microsoft site and did a copy paste of what they had in that example and still no go so in came the delay.
-
1 Attachment(s)
Re: Function works during step through but not on regular run
I know that they are almost identical. I copied it from Microsoft website and made a little modification just to make it work w/ OPTION EXPLICIT and OPTION STRICT set to ON.
I've made a test app that uses the modified class. Download this and compile to run it. Tell me if the problem still persists:
-
Re: Function works during step through but not on regular run
Quote:
Originally Posted by coolbiz
I know that they are almost identical. I copied it from Microsoft website and made a little modification just to make it work w/ OPTION EXPLICIT and OPTION STRICT set to ON.
I've made a test app that uses the modified class. Download this and compile to run it. Tell me if the problem still persists:
Problem is still there. Your file list box shows:
Code:
Files in /sprint on ftp.ftpname.com:
1: File1.jpg
2:
So I added the sleep delay of 10 ms in at the same place. Sure enough all 15 files poped up. Maybe the FTP server I'm connecting to is slow in its replies. On another note man your UI code is cleaner then mine.....
-
Re: Function works during step through but not on regular run
Hmm ... that is the wierd thing. It works fine for me w/o putting the delay in and I've tried it on my home and work PC. I'm wondering if you have updated your .Net framework to the latest version. Maybe, there lies the problem.
If that still does not solve your problem, I'd suggest to try out 3rd party component. There are bunch out there and some of them are pretty cheap :)
-
Re: Function works during step through but not on regular run
Quote:
Originally Posted by coolbiz
Hmm ... that is the wierd thing. It works fine for me w/o putting the delay in and I've tried it on my home and work PC. I'm wondering if you have updated your .Net framework to the latest version. Maybe, there lies the problem.
If that still does not solve your problem, I'd suggest to try out 3rd party component. There are bunch out there and some of them are pretty cheap :)
Yeah its goofy but at least I have a decent work around. Everythings up to date (Dot Net v1.1 SP1 with the MS patches) and like I said the delay, even only a couple ms works fine so I can live with it. Thanks for your help.
-Allan.
-
Re: Function works during step through but not on regular run
Tried the program from a couple other computers and a couple other servers. Sure enough I do think its server/connection/reply speed based. Some FTP's are just slower then others.
On another note I needed to be able to CHMOD the files after I transfered them but that functionallity is not built into the Microsoft FTP class so I put it in myself, maybe it will help someone else:
Code:
' Change a files attributes on the FTP Server.
Public Sub CHMOD(ByVal sAttributes As String, ByVal sFileName As String)
If (Not (m_bLoggedIn)) Then
Login()
End If
SendCommand("SITE CHMOD " & sAttributes & " " & sFileName)
If (m_iRetValue <> 200) Then
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If
End Sub
-Allan
-
Re: Function works during step through but not on regular run
do one thing put some time delay in the function processing so that the machince will get the time to process the files...