more ftp "huh"

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

more ftp "huh"

Post 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
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: more ftp "huh"

Post by c4s »

I can only guess: Maybe SetFTPDirectory(ftp,"/") didn't work? Put a Debug in front of it to check its return value.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: more ftp "huh"

Post by IdeasVacuum »

Can you not give the real directory name instead of "/" ?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: more ftp "huh"

Post 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.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: more ftp "huh"

Post 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.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: more ftp "huh"

Post 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 "/"?
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: more ftp "huh"

Post 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....
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: more ftp "huh"

Post 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.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: more ftp "huh"

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: more ftp "huh"

Post 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).
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Re: more ftp "huh"

Post 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.
Post Reply