Page 1 of 1

FTP problem

Posted: Tue Oct 14, 2008 7:01 pm
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

Posted: Tue Oct 14, 2008 7:10 pm
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?

Posted: Tue Oct 14, 2008 7:22 pm
by mag
I disable firewall
I add a test for Result

still the same

Posted: Tue Oct 14, 2008 8:24 pm
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

Posted: Wed Oct 15, 2008 8:14 am
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

Posted: Wed Oct 15, 2008 3:06 pm
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.

Posted: Wed Oct 15, 2008 3:18 pm
by mag
Thanks for the info. I will try ExamineFTPDirectory() soon.
I write again here about the resut with my Linux and Window server

Posted: Wed Oct 15, 2008 4:44 pm
by TerryHough
@mag
Check your PM. Sent you some code.