| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I installed xHB Professional (November 2007). 1. Do I have everything to write a simple (console) program that logs in to an FTP server and uploads (PUT) a single file to a specified directory? 2. Is there a sample of such program? (Preferably with all error- checking stuff.) TIA, Eugene |
|
#2
| |||
| |||
| Already found TIpClientFtp() class and .\Source\tip\tests \uploadftp.prg |
|
#3
| |||
| |||
| "Eugene F." <pm771.am@gmail.com> wrote in message news:e16b5a57-8128-4a32-9df8-ad09ec47274c@j22g2000hsf.googlegroups.com... >I installed xHB Professional (November 2007). > > 1. Do I have everything to write a simple (console) program that logs > in to an FTP server and uploads (PUT) a single file to a specified > directory? > > 2. Is there a sample of such program? (Preferably with all error- > checking stuff.) > > TIA, Eugene Hi Eugene Here is a sample from xHarbour CVS located in the Tip directory \xHarbour\tests\tiptest. /* Uploadftp.prg Send an file or list of files to ftp server */ #include "common.ch" FUNCTION MAIN( cMask ) LOCAL lRet lRet := TRP20FTPEnv( cMask ) ? lRet RETURN nil *+北北北北北北北北北北北北北北北北北北北北北北北北 北北北北北北北北北北 *+ *+ Static Function TRP20FTPEnv() *+ *+北北北北北北北北北北北北北北北北北北北北北北北北 北北北北北北北北北北 *+ STATIC FUNCTION TRP20FTPEnv( cCarpeta ) LOCAL aFiles LOCAL n LOCAL cUrl LOCAL cStr LOCAL lRetorno := .T. LOCAL oUrl LOCAL oFTP LOCAL cUser LOCAL cServer LOCAL cPassword LOCAL cFile := "" LOCAL lElim DEFAULT lElim TO .F. cServer := "ftpserver" //change ftpserver to the real name or ip of your ftp server cUser := "ftpuser" // change ftpuser to an valid user on ftpserer cPassword := "ftppass" // change ftppass to an valid password for ftpuser cUrl := "ftp://" + cUser + ":" + cPassword + "@" + cServer // Leemos ficheros a enviar aFiles := Directory( cCarpeta ) IF Len( aFiles ) > 0 oUrl := tUrl():New( cUrl ) oFTP := tIPClientFtp():New( oUrl, .T. ) oFTP:nConnTimeout := 20000 oFTP:bUsePasv := .T. // Comprobamos si el usuario contiene una @ para forzar el userid IF At( "@", cUser ) > 0 oFTP Url:cServer := cServeroFTP Url:cUserID := cUseroFTP Url:cPassword := cPasswordENDIF IF oFTP:Open( cUrl ) FOR each cFile IN afiles ? "arquivo : " + cFile[ 1 ] IF !oFtp:UploadFile( cFile[ 1 ] ) lRetorno := .F. EXIT ELSE lRetorno := .t. ENDIF NEXT oFTP:Close() ELSE cStr := "No se ha podido conectar con el servidor FTP" + " " + oURL:cServer IF oFTP:SocketCon == NIL cStr += Chr( 13 ) + Chr( 10 ) + "Conexi髇 no inicializada" ELSEIF InetErrorCode( oFTP:SocketCon ) == 0 cStr += Chr( 13 ) + Chr( 10 ) + "Respuesta del servidor:" + " " + oFTP:cReply ELSE cStr += Chr( 13 ) + Chr( 10 ) + "Error en la conexi髇:" + " " + InetErrorDesc( oFTP:SocketCon ) ENDIF ? cStr lRetorno := .F. ENDIF ENDIF RETURN lRetorno |
|
#4
| |||
| |||
| Bill, Thank you very much for your prompt reply. I'm wondering about the following part of the code: // Comprobamos si el usuario contiene una @ para forzar el userid // <below Google transation of the above comment> // Check if the user contains an @ to force the userid IF At( "@", cUser ) > 0 oFTP Url:cServer := cServeroFTP Url:cUserID := cUseroFTP Url:cPassword := cPasswordENDIF Why is "@" important? Is it just a way to distinguish between anonymous login and not that assumes that FTP ID is actually in an e- mail address format? Do you happen to know? TIA, Eugene |
|
#5
| |||
| |||
| "Eugene F." <pm771.am@gmail.com> wrote in message news:9743bfc2-4c37-4e0a-a18f-3c7b0f3b0111@d1g2000hsg.googlegroups.com... > Bill, > > Thank you very much for your prompt reply. > > I'm wondering about the following part of the code: > > // Comprobamos si el usuario contiene una @ para forzar el > userid > // <below Google transation of the above comment> > // Check if the user contains an @ to force the userid > IF At( "@", cUser ) > 0 > oFTP Url:cServer := cServer> oFTP Url:cUserID := cUser> oFTP Url:cPassword := cPassword> ENDIF > > Why is "@" important? Is it just a way to distinguish between > anonymous login and not that assumes that FTP ID is actually in an e- > mail address format? > > Do you happen to know? > > TIA, Eugene > Hi Eugene, I don't know why it's there. I have only used ftp clients such as WSftp to upload and download files. Windows has a command line ftp client that you can play with. Just go to the cmd prompt and type: ftp and type ? at the ftp> prompt. ftp> ? [Enter] |
|
#6
| |||
| |||
| Eugene, > // Check if the user contains an @ to force the userid > IF At( "@", cUser ) > 0 > oFTP Url:cServer := cServer> oFTP Url:cUserID := cUser> oFTP Url:cPassword := cPassword> ENDIF > >Why is "@" important? Is it just a way to distinguish between >anonymous login and not that assumes that FTP ID is actually in an e- >mail address format? The "@" means "at" as usual but it has nothing to do with email syntax. The tURL class expects the URL passed to the New() method, including login credentials, to be in the format "ftp://" + cUser + ":" + cPassword + "@" + cServer cServer can include the remote path and file name in addition to the server name This format is consistent with how ftp operations can be performed in Internet Explorer where the syntax to be used in the address field is ftp://username assword@hostnameThe tURL class parses the URL string using HB_Regex() and puts the different parts in various instance variables. But you can also call tUrl():New() with no arguments at all and populate the variables separately. This is an example of how I do it ... oUrl := TUrl():New() oUrl:cProto := "ftp" oUrl:cServer := cServer oUrl:cPath := cRemotePath oUrl:cFile := cRemoteFile oUrl:cUserid := cUserName oUrl:cPassword := cPassword oUrl:nPort := nPort .... where of course the variables on the right side are my local settings for the ftp job. Hope this helps Regards, Klas ------- klas dot engwall at engwall dot com http://www.engwall.com/clipper/ The LFN Library for Clipper The LanMan Library for Clipper The NFPAT1A Timeslice release patch for the Nanforum Toolkit |
|
#7
| |||
| |||
| Klas, Thank you very much for the response. <<< The "@" means "at" as usual but it has nothing to do with email syntax. The tURL class expects the URL passed to the New() method, including login credentials, to be in the format "ftp://" + cUser + ":" + cPassword + "@" + cServer >>> Yes, I know that. If you look at the sample I provided, the auathor was checking that "@" is present within cUser and not cServer. Am I still missing something? TIA, Eugene |
|
#8
| |||
| |||
| Eugene, [I posted this twice before but had no luck at reader.greatnowhere.com so both attempts were lost - and they say that 08.08.08 was supposed to be a lucky day <g>] ><<< The "@" means "at" as usual but it has nothing to do with email >syntax. The tURL class expects the URL passed to the New() method, >including login credentials, to be in the format "ftp://" + cUser + >":" + cPassword + "@" + cServer >>> > >Yes, I know that. If you look at the sample I provided, the auathor >was checking that "@" is present within cUser and not cServer. > >Am I still missing something? The sample code in CVS is not always consistent. There may have been several authors involved in that particular sample over the years. At the top of the function all the parts of cUrl are declared separately before they are put together ... cServer := "ftpserver" cUser := "ftpuser" cPassword := "ftppass" cUrl := "ftp://" + cUser + ":" + cPassword + "@" + cServer .... and sent to tUrl ... oUrl := tUrl():New( cUrl ) .... and then cUser is checked for "@" further down in the code. My guess is that originally everything was in cUser and that it was changed at a later date and that whoever made that change didn't notice the redundant "@" check. That is the only reasonable explanation I can think of. Note that in the line ... IF At( "@", cUser ) > 0 .... it is the local cUser that is being examined, not oUrl:cUserid. If the local variables had been set up differently, the code following that line would have populated some instance variables in tUrl, but now it does nothing. Regards, Klas ------- klas dot engwall at engwall dot com http://www.engwall.com/clipper/ The LFN Library for Clipper The LanMan Library for Clipper The NFPAT1A Timeslice release patch for the Nanforum Toolkit |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.