Computer Science Canada pseudo-FTP program |
Author: | Kronik [ Sat May 19, 2007 2:01 pm ] |
Post subject: | pseudo-FTP program |
I was wondering if it is possible to transfer files over a net connection. Right now I can transfer text files to a remote server but when I try to transfer non-ASCII files I receive 'Illegal Character' or one of various overflow errors. I have posted my current (working) client and server source below with some sensitive data removed. Any help is greatly appreciated. -Mike --------------------Begin Server Source-------------------- var netStream,fileStream,ret:int var ip,fileName,line:string var fileCheck:boolean const PORT:int:= %removed for security const PATH:string:= %removed for security const KEY:string:= %removed for security View.Set("title:ServerSide 1.0,invisible") procedure main netStream:=Net.WaitForConnection(PORT,ip) get:netStream,fileName fileCheck:=File.Exists(PATH+fileName) if fileCheck=false then system("copy "+PATH+"temp.txt"+fileName,ret) else end if open:fileStream,PATH+fileName,put loop if Net.LineAvailable(netStream)then get:netStream,line:* else end if exit when line=KEY put:fileStream,line+" " .. end loop close:fileStream Net.CloseConnection(netStream) end main loop main end loop ---------------------End Server Source--------------------- ---------------------Begin Client Source-------------------- var netStream,fileStream:int var fileName,line:string const PORT:int:= %removed for security const IP:string:= %removed for security const PATH:string:= %removed for security const KEY:string:= %removed for security View.Set("nobuttonbar,title:ClientSide 1.0") procedure main netStream:=Net.OpenConnection(IP,PORT) if netStream<=0 then View.Set("title:ClientSide 1.0 - Disconnected") else View.Set("title:ClientSide 1.0 - Connected ![]() end if get fileName put:netStream,fileName open:fileStream,PATH+fileName,get loop exit when eof(fileStream) get:fileStream,line put line+" ".. put:netStream,line end loop close:fileStream put:netStream,KEY put KEY Net.CloseConnection(netStream) end main main ----------------------End Client Source--------------------- |
Author: | DIIST [ Sat May 19, 2007 5:13 pm ] |
Post subject: | Re: pseudo-FTP program |
You need to use Net.ByteAvaliable, along with write and read functions to send byte by byte the data of the file across the net. There is no other way around it. . |
Author: | zylum [ Sat May 19, 2007 5:15 pm ] |
Post subject: | RE:pseudo-FTP program |
Look in to the read and write keywords. Basically the get and put parameters you use when opening a file tell the program that you will be reading in ascii values. The read/write parameters say you will be dealing with binary. |