FTP problem

Just starting out? Need help? Post your questions and find answers here.
mag
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Mar 29, 2004 1:46 pm

FTP problem

Post by mag »

I try to use FTP library. My server use Linux

Code: Select all

InitNetwork()
If OpenFTP(0, "*", "*", "*", 0) ;* hidden 
	Debug "FTP Conected"
  	SetFTPDirectory(0,"www")
  	Debug GetFTPDirectory(0)
	Result = SendFTPFile(0, OpenFileRequester("Choose a file to send", "", "*.*", 0), "purebasic_sent.file", 1)
  	Repeat
		Debug FTPProgress(0)
		Delay(300)
	Until FTPProgress(0) = #PB_FTP_Finished Or FTPProgress(0) = #PB_FTP_Error   
	Debug "Finished"
	CloseFTP(0)
Else
  	MessageRequester("Error", "Can't connect to the FTP server")
EndIf
The output is...
FTP Conected
/www
-1
-1
-1
-1
-1
-1
-1
Its not stop forever...

I check my server with smartFTP. The server is ok
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Have you got a firewall preventing access to the internet your PB application?

You don't check the result of SendFTPFile() - perhaps it has failed and you should not enter the loop?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
mag
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Mar 29, 2004 1:46 pm

Post by mag »

I disable firewall
I add a test for Result

still the same
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Try this

Code: Select all

InitNetwork()
If OpenFTP(0, "***", "***", "***") ;* hidden
  Debug "FTP Connected"
  
  ; SetFTPDirectory() - only an immediate directory change is allowed.
  ; To change to several levels of directory, this command will have to be called several time.
  ; Eg. SetFtpDirectory(Connect, "pub/support") is invalid on most servers.
  ; Some servers require directory names to match on case, so take care.
  ServerDirectory$ = "/www"  ; replace with your information <<<<<<<------
  For Ctr = 2 To CountString(ServerDirectory$, "/")+1
    SetFTPDirectory(0, StringField(ServerDirectory$,Ctr,"/"))
  Next
  
  ; Verifying server's current directory is correct.  Some delay is necessary
  While Directoryname$ = ""
    Delay(50)
    Directoryname$ = GetFTPDirectory(0)
  Wend
  Debug Directoryname$
  
  Filename$ = "C:\PureBasic.chm"
  
  Result = SendFTPFile(0, Filename$, GetFilePart(Filename$), #True)
  Debug Result
  
  If Result
    Repeat
      Delay(10)
    Until FTPProgress(0) = #PB_FTP_Started  ; -1
    Debug "The file transfer has been initialized."
    
    Repeat
      Delay(10)
      Result = FTPProgress(0)
      Select Result
      Case #PB_FTP_Error  ; -2
        Debug "Send/Recv error occurred."
        Break
      Case #PB_FTP_Finished  ; -3
        Debug FileSize(Filename$)  ; should actually be verified against remote file here
        Debug "The file transfer has finished."
        Break
        Default
        ; Show bytes tranferred
        Debug Result + 1
      EndSelect
    ForEver
    Delay(100)
    CloseFTP(0)
  EndIf
Else
  MessageRequester("Error", "Can't connect to the FTP server")
EndIf
mag
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Mar 29, 2004 1:46 pm

Post by mag »

Thanks a lot. its WORK
The version you give me is more proper way. I try to see where is actually the problem. I found it at the OpenFTP command..

This make it not work..

Code: Select all

If OpenFTP(0, "*", "*", "*", 0) ;* hidden 
This make it work..

Code: Select all

If OpenFTP(0, "*", "*", "*") ;* hidden


Probably because I make conection in active mode, my norton firewall block or whatever happen I don't understand
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

I should have noted for you that I removed the Active setting.

I haven't been successful using the FTP library to send/receive a file on an "Active" connection with either my Windows or Unix based servers. Not sure why. But since I only use "Passive" connections day to day, I just haven't worried about it.

AFAIK, the only problem that I still have with the FTP Library is the ExamineFTPDirectory() command when used with a UNIX/Linux based server where it delays for 3 minutes. That problem doesn't happen with my Windows based servers. I have reported this as a potential bug, but no reply so far.
mag
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Mar 29, 2004 1:46 pm

Post by mag »

Thanks for the info. I will try ExamineFTPDirectory() soon.
I write again here about the resut with my Linux and Window server
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

@mag
Check your PM. Sent you some code.
Post Reply