Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Upload Problem 1

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I have an app which has been working without errors for a number of months. The machine this app is used on was recently infected by a ransom virus - don't know how but that is not the issue. I have cleared the virus and it's associated files and the machine is back to full health except that the upload program only uploads an empty file. There are no errors, it just fails to upload any content in the file - all very odd and I ws wondering if anyone could offer any suggestions as to where the problem lies.

I have popped some wait windows in there to see what is happening and all seems to be running through the right path but only uploading an empty file. I have deleted te blank file off the server and each upload is replaced with a blank file.

This app is a variation of an FTP program and loads files from various locations to several servers and the result is the same loading different files to different servers.

Code:
PROCEDURE UPLOAD
	LNXFERTYPE = 1
	MESSY=0
	DECLARE INTEGER InternetOpen IN wininet.DLL;
		STRING  sAgent,;
		INTEGER lAccessType,;
		STRING  sProxyName,;
		STRING  sProxyBypass,;
		STRING  lFlags
	DECLARE INTEGER InternetCloseHandle IN wininet.DLL INTEGER hInet
	DECLARE INTEGER InternetConnect IN wininet.DLL;
		INTEGER hInternetSession,;
		STRING  lcHost,;
		INTEGER nServerPort,;
		STRING  lcUser,;
		STRING  lcPassword,;
		INTEGER lService,;
		INTEGER lFlags,;
		INTEGER lContext
	DECLARE INTEGER FtpPutFile IN wininet.DLL;
		INTEGER hConnect,;
		STRING  lpszLocalFile,;
		STRING  lpszNewRemoteFile,;
		INTEGER dwFlags,;
		INTEGER dwContext
	PUBLIC HOPEN, HFTPSESSION

	IF CONNECT2FTP (LCHOST, LCUSER, LCPASSWORD)
		IF FILE(SORSFILE)
			SORSFILE=LOWER(SORSFILE)
			IF FTPPUTFILE(HFTPSESSION, SORSFILE,DESTFILE, LNXFERTYPE, 0) = 1
				WAIT WINDOW 'File '+SORSFILE+' Transferred' nowait
				MESSY = 1
			ELSE
				WAIT WINDOW 'File '+SORSFILE +' TO '+ DESTFILE+' No transfer' nowait
				MESST = 2
			ENDIF
		ELSE
			WAIT WINDOW 'No file' nowait
			MESSY = 3
		ENDIF
		= INTERNETCLOSEHANDLE (HFTPSESSION)
		= INTERNETCLOSEHANDLE (HOPEN)
	ELSE
		WAIT WINDOW 'Cannot Connect' nowait
		MESSY=4
	ENDIF

ENDPROC



FUNCTION  CONNECT2FTP (LCHOST, LCUSER, LCPASSWORD)
	* open access to Inet functions
	HOPEN = INTERNETOPEN ("vfp", 1, 0, 0, 0)
	IF HOPEN = 0
		WAIT WINDOW "Unable to get access to WinInet.Dll" NOWAIT
		MESSY = 5
		RETURN .F.
	ELSE
		WAIT WINDOW "Connection Made" nowait
	ENDIF
	HFTPSESSION = INTERNETCONNECT (HOPEN, LCHOST,;
		0, LCUSER, LCPASSWORD, 1, 0, 0)   &&... 1 = ftp protocol
	IF HFTPSESSION = 0
		* close access to Inet functions and exit
		= INTERNETCLOSEHANDLE (HOPEN)
		MESSY = 6
		WAIT WINDOW "ftp " + LCHOST + " is not available" nowait
		RETURN .F.
	ELSE
		WAIT WINDOW "Connected to " + LCHOST  nowait
	ENDIF
	RETURN .T.
	RETURN

Keith
 
As you still hsitate:

I assume your code get's to the point WAIT WINDOW 'File '+SORSFILE +' TO '+ DESTFILE+' No transfer' nowait, right? That's the else branch of the IF FTPPUTFILE.
How about doing what the MSDN says about what to do, when FTPPUTFILE returns false (or 0)? Let GetLastError() tell you more about what didn't work:
Code:
LOCAL LNERROR
...
DECLARE INTEGER GetLastError IN kernel32

IF FTPPUTFILE(HFTPSESSION, SORSFILE,DESTFILE, LNXFERTYPE, 0) = 1
				WAIT WINDOW 'File '+SORSFILE+' Transferred' nowait
				MESSY = 1
ELSE
                                LNERROR = GetLastError()
				WAIT WINDOW 'Error ' + Transform(LNERROR)+': File '+SORSFILE +' TO '+ DESTFILE+' No transfer' nowait
				MESST = 2
ENDIF
GetLastError is an API function returning the error number for very many, not to say the most API functions.
The meaning of the errors can be looked up here: in the corrsponding link for the error number ranges.

Do this and see what FTPPUTFILE really reports as the reason for the faileing transfer.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top