> Hi,
>
> A while back I got this great code from this forum and it works really well for uploading to an FTP site. The problem is, I can't figure out how to get it to upload to anything but the root folder.
>
> Anyone know how I can modify to upload to a folder several levels down from the root?
>
> Thanks.
>
> Jill Lindgren
>
> ****************************************************************************************
> *: FTP UPLOAD CODE:
>
> PARAMETERS lcFileName
>
> Private pcNazwaZb,pcNazwaZbLoc,lpszServerName,lpszUsername,lpszPassword,;
> pcPathNazwa,pcNazwaZbWysLoc,pcPathWysNazwa
>
>
> #DEFINE INTERNET_OPEN_TYPE_DIRECT 1
> #DEFINE INTERNET_INVALID_PORT_NUMBER 0
> #DEFINE INTERNET_SERVICE_FTP 1
> #DEFINE INTERNET_FLAG_PASSIVE 0x08000000
> #DEFINE FILE_ATTRIBUTE_NORMAL 0x00000080
> #DEFINE FTP_TRANSFER_TYPE_BINARY 0x00000002
> #DEFINE FTP_ERROR "Error 1"
> #DEFINE FTP_KOMENT "Error 2"
> #DEFINE FTP_TRANSFER_TYPE_ASCII 0x00000001
> #DEFINE INTERNET_FLAG_TRANSFER_ASCII FTP_TRANSFER_TYPE_ASCII
> SET STEP ON
>
> DECLARE Integer InternetOpen IN WinINet ;
> string lpszAgent, integer dwAccessType, string lpszProxyName, ;
> string lpszProxyBypass, integer dwFlags
>
> DECLARE Integer InternetConnect IN WinINet ;
> integer hInternet, string lpszServerName, ;
> integer nServerPort, string lpszUsername, ;
> string lpszPassword, integer dwService, ;
> integer dwFlags, integer dwContext
>
> DECLARE INTEGER FtpPutFile IN wininet;
> INTEGER hConnect,;
> STRING lpszLocalFile,;
> STRING lpszNewRemoteFile,;
> INTEGER dwFlags,;
> INTEGER dwContext
>
> DECLARE integer InternetCloseHandle IN WinINet ;
> integer hInternet
>
> DECLARE INTEGER FtpGetCurrentDirectory IN wininet;
> INTEGER hFtpSession,;
> STRING @ lpszDirectory,;
> INTEGER @ lpdwCurrentDirectory
>
> DECLARE INTEGER FtpSetCurrentDirectory IN wininet;
> INTEGER hFtpSession,;
> STRING @ lpszDirectory
>
> WAIT WINDOW "Sending file via FTP" nowait
>
> hInternet = InternetOpen('Ftp',INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0)
>
> IF hInternet = 0
> = MESSAGEBOX(FTP_ERROR,64,FTP_KOMENT)
> RETURN
> EndIf
>
>
> lpszServerName = ALLTRIM(tblsettings.ftpaddr)
> lpszUsername = ALLTRIM(tblsettings.user)
> lpszPassword = ALLTRIM(tblsettings.pass)
> lpszDirectory = "web/GlobalWebCart/Stores/factoryservices/www/images/"
>
> pcNazwaZb = lcFilename
> pcNazwaZbLoc= lcFilename
> hConnect = InternetConnect(hInternet, lpszServerName, ;
> INTERNET_INVALID_PORT_NUMBER, ;
> lpszUsername, lpszPassword, ;
> INTERNET_SERVICE_FTP, 0, 0)
>
> IF hConnect = 0
> = InternetCloseHandle(hInternet)
> = MESSAGEBOX(FTP_ERROR,64,FTP_KOMENT)
> RETURN
> ENDIF
>
> ** lpszDirectory = ''
> ** lpdwCurrentDirectory = 0
>
> LOCAL cBuffer, nBufsize
> nBufsize = 260
> cBuffer = REPLICATE(CHR(0), nBufsize)
> nRetCode = FtpGetCurrentDirectory(hConnect, @cBuffer, @nBufsize)
>
> nRetCode = FtpSetCurrentDirectory(hConnect,'dirname/upload')
>
> nBufsize = 260
> cBuffer = REPLICATE(CHR(0), nBufsize)
>
> nRetCode = FtpGetCurrentDirectory(hConnect, @cBuffer, @nBufsize)
>
> nRetCode = FtpPutFile(hConnect,pcNazwaZbLoc,pcNazwaZb,INTERNET_FLAG_TRANSFER_ASCII,0)
> = InternetCloseHandle(hInternet)
>
> MESSAGEBOX("FTP sent")
> Return
Should you use this as your target directory?
lpszDirectory = "web/GlobalWebCart/Stores/factoryservices/www/images/"
nRetCode = FtpSetCurrentDirectory(hConnect,lpszDirectory)
Mike Gagnon
Refox XI +(English version)