FTP Problem

Post Reply
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

FTP Problem

Post by Jeff Barnes »

Hi Everybody,

I am trying to send a file to a FTP server and it appears to work (ie: no errors) and it does create a file name on the server but the size is always 0KB.

The size should be 1,560KB

The code is below.

Can someone please tell me where I am going wrong?

Code: Select all

FUNCTION FtpSendFile( cFTPSite, cSource, cTarget, cUser, cPass, nBufSize )
   LOCAL oInternet, oFTP

   DEFAULT cUser:="", cPass:="", nBufSize:=2000
   IF EMPTY(cFtpSite) .or. EMPTY(cSource) .or. EMPTY(cTarget)
      MsgInfo("Missing Parameters"+chr(13)+"Usage: FtpSendFile(cFtpSite, cSource, cTarget, cUser, cPass, nBufSize)  ","FtpSendFile()")
      Return .f.
   ENDIF

    oInternet := TInternet():New()
    IF Empty( oInternet:hSession )
       MsgAlert( "Internet session not available!" )
    ELSE
       oFTP := TFTP():New( cFTPSite, oInternet, cUser, cPass )
       IF Empty( oFTP:hFTP )
          MsgStop( "Cannot connect to "+cFtpSite )
          oInternet:End()
          return .f.
       ENDIF
    ENDIF

    SendFiles( cSource, cTarget, nBufSize, oFTP )
    Syswait(.05)
    oInternet:End()
return .t.

static function SendFiles( cSource, cTarget, nBufSize, oFTP )
   local hSource
   local cBuffer := Space( nBufSize )
   local nBytes
   local oFile

   if ! File( cSource )
      MsgStop( "File not found: " + cSource )
      Return .f.
   endif

   hSource = FOpen( cSource )
   oFile = TFtpFile():New( cTarget, oFTP )
   oFile:OpenWrite() 
   FSeek( hSource, 0, 0 )
   nFile := 0
   SysRefresh()

   while ( nBytes := FRead( hSource, @cBuffer, nBufSize ) ) > 0
      oFile:Write( SubStr( cBuffer, 1, nBytes ) )
      SysRefresh()
   end
   FClose( hSource )
   oFile:End()
return .t.

Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

If this is not the best approach to sending a file over the internet could someone please show me a different way of doing it?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

I just tried sending the file form a different computer ... it works ... the file size was not 0KB.

Can anyone suggest a reason why it might not work from one computer does from another?

I would think a router issue but the actual file name gets created.

I'm confused :?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Richard Chidiak
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France
Contact:

Post by Richard Chidiak »

Jeff

I had the same problem some time ago, very confusing.

I changed to xharbour's native ftp and since everything is OK

here is the code i use,

note you must include tip.ch in your program

hth

Richard

Code: Select all

cUrl := "ftp://" + cUser + ":" + cPassword + "@" + cServer
oUrl := tUrl():New(cUrl)

oFtp := tIPClientftp():New(oUrl,,.t.)
oFtp:nConnTimeout := 20000
oFtp:bUsePasv     := .t.

IF oFtp:open(cUrl)
   IF oFtp:UpLoadFile((cFile))  // upload ok
    ELSE
      MSGSTOP(.......) 
   ENDIF
   oFtp:Close()
 ENDIF
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Sheng
Posts: 15
Joined: Mon Sep 29, 2008 1:41 pm

Post by Sheng »

Jeff Barnes wrote:I just tried sending the file form a different computer ... it works ... the file size was not 0KB.

Can anyone suggest a reason why it might not work from one computer does from another?

I would think a router issue but the actual file name gets created.

I'm confused :?
firewell ?
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Thanks Richard.

It works from both computers :-)


But I did run into another issue ... maybe you could help me.

It connects to my FTP server at home with no problems but when I try to connect to my hosted FTP it will not connect.

I type the ftp:// address in my browser and that works so I know I've got the correct address/user/password. From within the program it does not.

If I try the original method it does connect but I am back to the 0KB file size.

Any ideas?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
Post Reply