I have some files that I upload via ftp and some are *.doc and some *.docx and also *.pdf. I am having trouble with formatting the correct extensions and also working with spaces in file name, if there is file names and it's a *.docx 4 char extension all works but if not I get errors. I have prepared some sample code with special information removed for security purposes.
The process is that user selects file to upload I use the shell to run and AES encryption to the file and then delete the unencrypted file, and upload to server via ftp then delete the uploaded *.aes encrypted file, write to sql database the filename derived from the description. Like I said works fine if there is a 4 char extension and no spaces in the filename of the selected file.
Here is the code I am using
The process is that user selects file to upload I use the shell to run and AES encryption to the file and then delete the unencrypted file, and upload to server via ftp then delete the uploaded *.aes encrypted file, write to sql database the filename derived from the description. Like I said works fine if there is a 4 char extension and no spaces in the filename of the selected file.
Here is the code I am using
Code:
'Date Created: 31-Mar-2016 09:59:28 AM 'Last Updated: 21-Feb-2018 01:59:58 PM 'Created By : Steve 'Updated By : hubby 'Prompt for text and store result in a variable called 'ftype'. 'Get 'Value' property of 'Idclientd' in Form 'clientstart' . DIM window_name as C window_name = ":"+"credmaster" DIM varP_Object as p 'Get a pointer to the specified window varP_Object = obj(window_name) 'Check if the specified window exists if .not. is_object(varP_Object) then ui_msg_box("Error","The window '"+window_name+"' does not exist.",ui_stop_symbol) else DIM SHARED clientid AS n clientid = varP_Object:Idclientd.value end if dim prmpt_title as c dim prmpt_prompt as c dim prmpt_default as c prmpt_title = "Description" prmpt_prompt = "File Description" prmpt_default = "" DIM SHARED ftype AS C ftype = ui_get_text(prmpt_title,prmpt_prompt,prmpt_default) 'Prompt for a filename and store result in a variable called 'fname'. 'Prompt for a filename and store result in a variable called 'fname'. dim prmpt_title as c dim prmpt_filter as c dim prmpt_default as c dim prmpt_flag as c prmpt_title = a5_eval_expression("=\"Choose File\"",local_variables()) prmpt_filter = "(*.*)" prmpt_default = "" DIM fname AS C fname = ui_get_file( a5_eval_expression(prmpt_title,local_variables()),prmpt_filter,prmpt_default,"X") if ftype ="" ui_msg_box("error","You Didn't Choose a File Description",UI_STOP_SYMBOL) end end if if fname="" ui_msg_box("error","You Didn't Choose a File",UI_STOP_SYMBOL) end end if sys_shell_wait("c:\housing\aescrypt -e -p magic_key_removed "fname,.F.) dim extn as c extn = right(fname,4) xbasic_wait_for_idle(2) dim st as c dim en as c st = "\\" en = " " dim shared upname as c upname=".aes" dim ftsend as c ftsend=ftype+"."+extn+upname cmd = <<%a% connect|******** onerror|error|Could not connect login|*****|******* onerror|error|Could not log in mkdir|%a%"/srv/ftp/clientdocs/credit/" + clientid + crlf() + <<%a% onerror|quit quit %a% ftp_script_run_silent(cmd, .t.) ftp_put_file("192.168.69.149", "******", "******", fname+".aes","/srv/ftp/clientdocs/credit/"+clientid+"/"+ftsend,.f.,"Uploading File") 'Insert a new record into a remote SQL database. 'DIM a connection variable DIM cn as SQL::Connection dim flagResult as l flagResult = cn.open("::Name::pat") if flagResult = .f. then ui_msg_box("Error","Could not connect to database. Error reported was: " + crlf() + cn.CallResult.text) end end if 'Specify that we are using Portable SQL syntax cn.PortableSQLEnabled = .t. dim shared agent as c agent=user_name() 'Dim a SQL arguments object, create arguments and set their values DIM args as sql::arguments if a5_eval_valid_expression("=clientid",local_variables()) then args.add("idclientd",convert_type(a5_eval_expression("=clientid",local_variables()),"N")) end If if a5_eval_valid_expression("=ftsend",local_variables()) then args.add("doc_type",convert_type(a5_eval_expression("=ftsend",local_variables()),"C")) end If if a5_eval_valid_expression("=agent",local_variables()) then args.add("doc_who",convert_type(a5_eval_expression("=agent",local_variables()),"C")) end If dim sqlInsertStatement as c sqlInsertStatement = <<%txt% INSERT INTO cred_docs (idclientd, doc_type, doc_who) VALUES (:idclientd, :doc_type, :doc_who) %txt% dim flag as l flag = cn.Execute(sqlInsertStatement,args) if flag = .f. then ui_msg_box("Error","Record was not inserted. Error reported was: " + crlf(2) + cn.CallResult.text,UI_STOP_SYMBOL) else if cn.AffectedRows() = 1 then ui_msg_box("Notice","File Has Been Uploaded..",UI_INFORMATION_SYMBOL) else ui_msg_box("Error","File Has Not Been Uploaded." ,UI_STOP_SYMBOL) end if end if cn.close() xbasic_wait_for_idle(1) file.remove(fname) file.remove(ftsend) delete fname delete ftsend
Comment