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
 
Where in the code is SORSFILE set? That's what you pass in as the file name to transfer. It doesn't even come in as a parameter to your Upload Procedure. FTPPUTFILE opens that file, reads it, uploads it, and closes it. It's pretty self contained, and once the FTPPUTFILE returns 1 (TRUE) you can be sure both the connection was valid, the file was found, transferred etc. and the whole process was successful from the point of view of the wininet.dll. Otherwise you would get into the else branch displaying a transfer error. If it isn't found at the destination FTP Server, there's pretty much nothing you can debug at your side. Someone at the destination FTP server would need to look, what's going on there and isn't reported back to your FTPPUTFILE call.

You could of course double check your wininet.dll and related system files, try with a newly installed PC etc.

Bye, Olaf.
 
Thanks Olaf - that is the next stage but it just stopped working.
SORSFILE and DESTFILE are declared as public vars, I know it is not the way to do it but this prog is still under development and has been working fine for some time. I have tested it as a stand alone prog with the vars declared in the prog but with the same result.

Strange thing is, it is working as before but just not transferring the file contents and this is happening on different file / server combinations too.


Keith
 
So, if that happens to different servers and with differetn files, can you test on another client PC? If it works from anohter PC your computer is not virus free yet, perhaps, cause damage to wininet.dll for example or anything related.

Bye, Olaf.
 
Thanks Olaf
I will have a look to see if I can get wininet.dll off the CD to replace it, I didn't want to start blindly replacing files if there was a simple explanation.

Keith
 
You can't replace a system DLL that way yourself. Or are you at Win9x? In the serious case even your virsuscanner is infected to report back no infection, you will need to reinstall. That's why you should first test your code on another client PC to see, if it's your code or your PC failing.

Bye, Olaf.
 
This difference may mean nothing. Explorer can display "size on disc", a multiple of block size, and block size on HDD and CD/DVD can differ.

Bye, Olaf.
 
I think your problem with the nonworking PC is more serious and you should consider reinstalling it completely, not only reinstall VFP. The functionality of FTPPUTFILE is a functionality of Windows you use within VFP, as that doesn't work it points to more damage done by the virus, than you think.

Reinstall Windows and Foxpro. If you made an image of your system (eg by norton ghost or acronis) then start from there.

Reinstalling Foxpro does nothing to the FTP Functions of Windows.

Bye, Olaf.
 
Oh no, I don't think "Network Places" uses the same functions.

Windows at least has wininet and the FTP DOS command has a different base and any FTP program would rather have is own implementation, or use something like curl.

You have the proof it's your PC, that's not working, Wininet is Windows Internet, it's not a part of VFP, so you have the proof it's a system problem. So what should Reinstalling VFP help?

Bye, Olaf.
 
You could try just one more thing on your broken system:

DECLARE any other Windows API function, eg Sleep() or anything you can test right away without a remote server involved. If that works you know it's also not the vfp runtime and DECLARE, which is broken.

Then put in concrete values for a file name and the other parameters of FTPPUTFILE, use another FTP server, so you can also rule out a configuration and parameterisation issue.

You may also simply try a fox reinstall, but don't come back, if it doesn't solve anything. I still deduct from all you say, this will not solve anything, even though your Network Places still works. You also still can use the internet and post here.

Your program would notify you, if the connection couldn't be made or the you ftp doesn't exist, so the only thing that fails is FTPPUTFILE, and that is a function within Wininet. Theres nothing more atomic on this level, that could be broken, and there is nothing on the foxpro level here, foxpr is just making the call, anything before it and after it works inside foxpro, you would be notified about connection problem, file not existing and such errors.

So, what reasoning does a foxpro reinstall have?

Bye, Olaf.
 
File exists or
Code:
WAIT WINDOW 'No file' nowait
would display - I have run it without the nowaits in and it is also failing on the app which has preset filenames on buttons which previously worked.

Looks like it is going to be a Windows install, I will put a bigger hard drive in at the same time.
Thanks Olaf

Keith
 
Yes, I know, in the bigger context I said:
Your program would notify you, if the connection couldn't be made or the file you ftp doesn't exist
So I read your code.

Bigger hard drive always is a good idea. Good luck.

Bye, Olaf.
 
What version? Since Vista it's merely a thing of 10-20 minutes to install the OS itself. What still takes much time is downloading ans installing all Updates, if there is no SP. And of course all other needed Software. Especially SQL Server, if you have that.

It really pays to invest 50 bucks into an imaging software and do an image of the system, that can't be replaced by backups and doesn't replace backups, but is a regular, yet more seldom additional step to take.

I do a first image afte OS installation including all Windows Updates, then after some essential software installs or at least once each quarter year. The system doesn't change so frequent. And don't overwrite the last image.

A virus infection might turn out later than you already stored it into an image and so you might want to revert to an earlier image. And it doesn't have to be a virus, it can be any instability, driver or codec problem, which you only detect with a time lag. As you don't want to revert everything to what it was half a year before or longer, data/document backups are of course still important. Once you have recovered to a clean system you can also scan backups for viruses before restoring from them, or avoid a Windows KB update to avoid a problem it caused, or whatever else troubled you and made you revert to an earlier stage.

Bye, Olaf.
 
I am running XP on this machine as I have some quite old software on there in order to support apps and scripts written years ago.

Installing the OS is pretty painless but then Apache server, Mysql and all the other programs have to be reinstalled so that the correct drivers are loaded and then the unexpected happenings of programs which ran before but have stopped running for no apparent reason.
A 20 minute job becomes a couple of days endlessly waiting for CDs to empty their contents onto a hard drive.
Why can't we simply go into a computer shop and buy a complete, read only, operating system on a Flash Drive and install additional required drivers together with the installed software. Each application would be in a different directory and programs would not share drivers and break something when one of them is updated.
More importantly, a virus would not be able to attack the operating system because the flash drive could not be written to.

Keith
 
Software is not only vulnerable on the disc drive, even more so in RAM. That's why this idea would only make it harder for a OS vendor to extend or fix it's OS. We had that time, but there was no internet way back then. There was C64 with it's OS in ROMs, Also Atari TOS. Those were the computers you turned on and that were ready instantly. It wasn't bad.

Image take much of this pain out. As you need to start from scratch, why not take the opportunity and install Apache and MySQL within a virtual machine. That can even easier be restored or reset, as the whole computer merely is a file. Such sub systems are easier to maintain as such virtual machines, you can do these things on Linux, were they are working even better than the Windows ported versions. I even outsourced this with an always on 5 Watts system called Raspberry Pi. Not finished with it, yet, but it should work very well.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top