Page 1 of 1

more ftp "huh"

Posted: Wed Feb 16, 2011 11:46 pm
by jassing
in this code -- what is wrong with line 11? (the ExamineFTPDirectory() line...)

Code: Select all

InitNetwork()
Debug "opening ftp"
ftp = OpenFTP(#PB_Any,"aiweather.com","xxx","xxx",#False)
If ftp
	Debug "Setting to root"
	Delay(1000)
	SetFTPDirectory(ftp,"/") 
	
	Debug "Examine folder"
	Delay(1000)
	If ExamineFTPDirectory(ftp)
		Delay(1000)
		While NextFTPDirectoryEntry(ftp)
			Delay(1000)
			Debug FTPDirectoryEntryName(ftp)
		Wend
		Delay(1000)
		FinishFTPDirectory(ftp)
	EndIf
	Delay(1000)
	CloseFTP(ftp)
Else
	Debug "Failed to open"
EndIf
Image

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 12:22 am
by c4s
I can only guess: Maybe SetFTPDirectory(ftp,"/") didn't work? Put a Debug in front of it to check its return value.

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 1:26 am
by IdeasVacuum
Can you not give the real directory name instead of "/" ?

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 1:40 am
by LuCiFeR[SD]
on my test FTP servers here... the code ran fine as long as I set it to passive mode, otherwise I got no directory listing, just blank. I had no IMA in either case.

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 3:50 am
by jassing
c4s wrote:I can only guess: Maybe SetFTPDirectory(ftp,"/") didn't work? Put a Debug in front of it to check its return value.
I did; same thing.

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 3:51 am
by jassing
IdeasVacuum wrote:Can you not give the real directory name instead of "/" ?
Someone here said you must change directories one at a time.
And how would I return to the root w/o changing to "/"?

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 3:54 am
by jassing
Just go this one...
Image

That's giving me the impression that the pb stuff isn't for prime time -- I mean; how can that have been screwed up?
And I had a sniffer going, it did not make contact to the server -- so it's not that my server gave it a response it couldn't handle....

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 5:43 am
by Frarth
Test SetFTPDirectory(). If it is 0 it could not be set:

Code: Select all

InitNetwork()
Debug "opening ftp"
ftp = OpenFTP(#PB_Any,"aiweather.com","xxx","xxx",#False)
If ftp
  Debug "Setting to root"
  Delay(1000)
  If SetFTPDirectory(ftp,"/") <> 0
    ; directory successfully set
    Debug "Examine folder"
    Delay(1000)
    If ExamineFTPDirectory(ftp)
      Delay(1000)
      While NextFTPDirectoryEntry(ftp)
        Delay(1000)
        Debug FTPDirectoryEntryName(ftp)
      Wend
      Delay(1000)
      FinishFTPDirectory(ftp)
    EndIf
    Delay(1000)
    CloseFTP(ftp)
  EndIf
Else
  Debug "Failed to open"
EndIf
Also, only unix-like servers are supported for directory listing. This may also be a clue.

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 8:57 am
by C64
jassing wrote:how can that have been screwed up?
When an illegal memory access error occurs, it's not always necessarily directly related to the highlighted line (it can be an on-flow error). So make sure everything else in your code prior to that line is 100% perfect, just to be sure.

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 12:05 pm
by Trond
If the code in the first post screenshot is the only code in the program, then ExamineFTPDirectory() shouldn't give an invalid memory access, and it's a bug in PB.

However, the use of SetFTPDirectory() is wrong.
jassing wrote:
IdeasVacuum wrote:Can you not give the real directory name instead of "/" ?
Someone here said you must change directories one at a time.
And how would I return to the root w/o changing to "/"?
Yes, you must change directories one at a time, it's clearly spelled out in the manual (and is the case for all ftp connections as far as I know). This means that if you're in /some/subdirectory/deep/down then SetFTPDirectory("/") is invalid. This should be obvious, as it's clearly trying to change multiple levels at a time.
To get to the root use SetFTPDirectory("..") several times (although I don't see why you would need it, as you start in the root directory when you are logged in).

Re: more ftp "huh"

Posted: Thu Feb 17, 2011 4:11 pm
by TerryHough
Trond wrote:Yes, you must change directories one at a time, it's clearly spelled out in the manual (and is the case for all ftp connections as far as I know). This means that if you're in /some/subdirectory/deep/down then SetFTPDirectory("/") is invalid. This should be obvious, as it's clearly trying to change multiple levels at a time.

To get to the root use SetFTPDirectory("..") several times ....
Actually, Trond, SetFTPDirectory(Connect,"/") is completely valid to return to the root directory. Test it, you will see.

Yes, SetFTPConnection(Connect,"/example/test/files") is invalid. It requires three separate SetFTPConnection commands to accomplish the change

Code: Select all

  ServerDirectory$ = "/example/test/files" 
  For Ctr = 2 To CountString(ServerDirectory$, "/")+1 
    SetFTPDirectory(Connect, StringField(ServerDirectory$,Ctr,"/")) 
  Next 
After that a GetFTPDirectory(Connect) would return "/example/test/files/".
Then issue a

Code: Select all

SetFTPDirectory(Connect,"/")
and after that a GetFTPDirectory(Connect) would return "/".

Again, if the current directory is "/example/test/files" then
a SetFTPDirectory(Connect,"/example") is completely OK.
But a SetFTPDirectory(Connect,"/example/test") is not correct.

PB's SetFTPDirectory() command does not support subpaths. This may be on
purpose because I have seen some FTP servers that won't handle subpath changes
that way too.

I've recently checked issuing subpath CDs manually on my two main servers and
both of them accepted the command and changed directories correctly. FTP
servers continue to be a challenge after all these years.