FTP Problem

FTP Problem

Postby Jeff Barnes » Wed Oct 22, 2008 2:15 am

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  Expand view
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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Jeff Barnes » Wed Oct 22, 2008 3:13 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Jeff Barnes » Wed Oct 22, 2008 4:14 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Richard Chidiak » Thu Oct 23, 2008 5:54 am

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  Expand view
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
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby Sheng » Thu Oct 23, 2008 8:14 am

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 ?
Sheng
 
Posts: 15
Joined: Mon Sep 29, 2008 1:41 pm

Postby Jeff Barnes » Fri Oct 24, 2008 1:41 am

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 89 guests