curly
Full Member
Posts: 161
|
Post by curly on Aug 19, 2021 3:35:19 GMT -5
Hi,
I suspect I might need to farm this out, but just in case......
When the user finishes his report using my application, the resulting file needs to be copied from the tablet to a remote server. The tablet contains a SIM card and can use the mobile phone network. Are there any commands in LB that may be able to automate this process? Maybe attach the file to an email or even upload using a vpn?
Kind regards,
David
|
|
|
Post by tenochtitlanuk on Aug 19, 2021 10:58:49 GMT -5
Code below is as used on three programs on my website to upload files on my local machine to my remote webserver. Works OK for me with LB under Linux/Wine. Can't remember who I got this from... Obviously you need to change the ftp address of your site and username/password.
nomainwin
dim error$(6000)
error$( 0) ="No problem.." error$(1003) ="user not connected to server" error$(1004) ="cannot open file" error$(1008) ="action not taken" error$(1010) ="server cannot open file" error$(3001) ="3001" error$(5002) ="5002"
WindowWidth = 100 WindowHeight = 40 UpperLeftX = 1 UpperLeftY = 1
port = 21 'port to use pasv = 1 'PASV mode? 1 is yes, 0 is no ftphost$ = "ftp.ddddddd.uk" 'ftp site address login$ = "plghplgh[" 'ftp site username login password$ = "plgh[plgh" 'ftp site password initpath$ = "" 'leave blank if you want the site's default upload$ = "IOT.txt" 'full path & file info for file to upload remotefile$ = "IOT.txt" 'what you want it to be called on the ftp server
TRUE = 1 FALSE = 0
ftpsession = FALSE
open "LB" for window as #main
#main, "trapclose [quit]"
hW =hwnd( #main)
[upload] parentftp =hW '
open "ftp4w32.dll" for dll as #ftp
ftpsession = TRUE
calldll #ftp, "FtpInit", parentftp as long, res as long calldll #ftp, "FtpSetSynchronousMode", dummy as long calldll #ftp, "FtpSetDefaultPort", port as long, dummy as long calldll #ftp, "FtpSetPassiveMode", pasv as long, dummy as long calldll #ftp, "FtpLogin", ftphost$ as struct, login$ as struct, password$ as struct, parentftp as long, 0 as long, res as long calldll #ftp, "FtpCWD", initpath$ as struct, res as long calldll #ftp, "FtpSendFile", upload$ as struct, remotefile$ as struct, 0 as long, 0 as long, parentftp as long, 0 as long, res as long
wait
[closeftp] calldll #ftp, "FtpCloseConnection", dummy as long calldll #ftp, "FtpRelease", dummy as long close #ftp ftpsession = FALSE wait
[quit] close #main if ftpsession = TRUE then calldll #ftp, "FtpCloseConnection", dummy as long calldll #ftp, "FtpRelease", dummy as long close #ftp end if end
|
|
curly
Full Member
Posts: 161
|
Post by curly on Aug 21, 2021 9:56:03 GMT -5
Hi tenochtitlanuk, Thank you very much! I never dreamt this would be possible! Being a very basic novice, your code sails well over my head. I've printed it, and read it, but still cannot understand it. If I say please really nicely, do you think you could put some very basic notes alongside relevant lines to explain what it is doing please? I'm OK down to, port = 21 Is this something I choose or our IT man will give me? pasv =1 I haven't a clue what pasv is? ftphost$ I know ftp is 'file transfer protocol' but don't know how to detail our site address. Our website is www.DSAElectrical.com We have fixed IP addresses I assume our IT man will give me a username and password? initpath$ = "" I assume the drive and directory where the file is to go goes here? upload$ I assume this is the name and location of the file I want to upload? remotefile$ I can rename the file as it is being uploaded? I'm completely lost from here on? Kind regards, David
|
|
|
Post by tenochtitlanuk on Aug 21, 2021 14:42:03 GMT -5
Yes, ftp- 'file transfer protocol'- allows you to send a file from one computer to another over the internet. Almost all the code you can simply use as a blackbox. The lines you need to change are already commented and I add more detail below. For the method I gave, you need the file 'ftp4w32.dll' in the folder where your LB program is. You can download it via an internet search, or from my site at diga me!You won't need to alter these two lines- passive mode on port 21 is standard. port = 21 'port to use pasv = 1 'PASV mode? 1 is yes, 0 is no
If the file you wish to upload will be put into the remote computer's root folder you do not need to change initpath$. If you have a folder on the remote server called 'data' that you want the file to go into you's set initpath$ to 'data'. initpath$ = "" 'leave blank if you want the site's default
upload$ is the name of the file you want to upload from the directory holding the LB program. remotefile$ is what you want it called on the server. Usually these will both be the same name upload$ = "IOT.txt" 'full path & file info for file to upload remotefile$ = "IOT.txt" 'what you want it to be called on the ftp server. Yes, can be different to source name.
ftphost$ = "ftp.ddddddd.uk" 'ftp site address login$ = "plghplgh[" 'ftp site username login password$ = "plgh[plgh" 'ftp site password
ftphost$ will be 'ftp.DSAElectrical.com' or 'DSAElectrical.com'. Try both and see which works! Yes, your IT man will give you the username and password- if he trusts you! If not you COULD use a personal webserver- I pay for a server but you CAN set your own up locally- but you'd need to know how to make it visible outside your personal network. You don't need to understand the rest of the code. If the hostname, username and password are correct the file that was in the folder on your computer should now be in the folder on the remote server computer. If you now start a web browser and enter as url 'www.DSAElectrical.com/IOT.txt' ( or whatever name/pathname you chose) you should see the text file displayed. If you upload an image file it would be displayed. If it's zipped it should offer to unzip. If it doesn't know the file type it will offer to download it into your Downloads folder. I can't help much further- but your 'IT man' should understand what's going on... best of luck.
PS There is a small window which opens on your screen. It will self-close after a timeout, or you can click the close icon on it.
|
|
curly
Full Member
Posts: 161
|
Post by curly on Aug 22, 2021 16:35:50 GMT -5
Thank you very, very much.
|
|
curly
Full Member
Posts: 161
|
Post by curly on Aug 24, 2021 3:34:46 GMT -5
Hi again,
Not quite finished, it seems we will need to buy an ftp server to send files direct?
I've found an old post, 'Sending email using Liberty basic', Dec 4th 2019 at 2:22pm, with code posted by Rod. It doesn't appear to my novice brain to include an attachment, and I don't know if it sends fully automated or needs user input? If it could send totally autonomously, and carry a file attachment, well, that would be magnificent! The code I found is below.
Kind regards, David
'email.bas 'based on the work done by Alyce Watson in EditWorks (Thanks ' you are an inspiration to all of us!) 'Runs on LB3.x 'Modifacations by Brad Moore (blame Alyce if it don't work) ;-)
[WindowSetup] NOMAINWIN WindowWidth = 136 : WindowHeight = 73 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
[ControlSetup]
button #main.email, "Email Me",[email],UL, 10, 10, 105, 25
Open "Window Title" for Dialog as #main
print #main, "trapclose [quit]" print #main, "font ms_sans_serif 10"
hWnd = hWnd(#main)
[loop] Wait
[quit] close #main : END
[email] 'The email address is ficticious, so don't bother pressing send... file$="mailto:whoever@coolISP.com?Subject=I want to be your friend" result = ShellExecute(hWnd, file$, "") if result <= 32 then notice "Error, Address Failure!" goto [loop]
Function ShellExecute(hWnd, file$, dir$)
parameter = _SW_SHOWNORMAL ' set up for viewing lpszOp$ = "open" + Chr$(0) ' "open" or "print" lpszFile$ = file$ + Chr$(0) lpszDir$ = dir$ + Chr$(0) lpszParams$= "" + Chr$(0)
CallDLL #shell32, "ShellExecuteA", _ hWnd As ulong, _ lpszOp$ As Ptr, _ lpszFile$ As Ptr, _ lpszParams$ As Ptr, _ lpszDir$ As Ptr, _ parameter As Long, _ result As Long
ShellExecute = result
End function
|
|
|
Post by tenochtitlanuk on Aug 24, 2021 3:51:05 GMT -5
Not quite sure what you have available. DSAelectrical.com is obviously hosted on a server. It will accept ftp connections. If you want to try the e-mail +attachment route, have a look at one of my many LB pages e-mail sender
|
|
|
Post by metro on Aug 24, 2021 4:58:10 GMT -5
I quite often update files for my office at home via dropbox, is that an option?
|
|
curly
Full Member
Posts: 161
|
Post by curly on Aug 24, 2021 6:29:18 GMT -5
Hi Metro, Thank you for your suggestion. I'm looking to use a button to attach the current file to an email and send without any other interaction. Our mail handler will strip the attachment from the email on arrival and move it to the correct location in our server. Hi tenochtitlanuk, found your website thank you. The code I attached works fine, but requires the attachment added manually and the send button clicked. I'm really hoping someone who understands the commands in the code can fix the issue for me? ???Although we have our own servers in the office, our website and mail is hosted for us by a third party. Kind regards, David
|
|
|
Post by Brandon Parker on Aug 24, 2021 10:22:02 GMT -5
That is only a matter of filling in the necessary parameter programmatically and calling the code that executes the send portion programmatically.
{:0)
Brandon Parker
|
|
curly
Full Member
Posts: 161
|
Post by curly on Aug 26, 2021 7:20:23 GMT -5
Hi Brandon, thank you very much. I'll try to work that out and advise. Kind regards, David
|
|
curly
Full Member
Posts: 161
|
Post by curly on Aug 31, 2021 8:21:24 GMT -5
Hi Brendon, I've searched and read and tried everything I can think of, but can't work out how to insert the correct parameters. Any chance you can give me a little guidance please? Kind regards, David
|
|
|
Post by Brandon Parker on Aug 31, 2021 15:15:16 GMT -5
Hello David, If you are using a properly formatted string for inserting an attachment and it is not working, it is highly likely that the program you are invoking to send the mail does not actually support the attachment function. Some do and some do not, but I do not think it is officially supported in the "mailto:" standard. This is a known "thing" and is the source of some strife out in the world. You can use mapi32.dll if you really want a headache on your hands. Here is a thread from a while back using it. libertybasiccom.proboards.com/thread/1257/mapisendmail-nightmareOr, ... I would actually use the sendEmail command-line program to send emails. This is how the program I developed at my previous employer sent emails. The program, written in Pearl, can be found at the link below. caspian.dotconf.net/menu/Software/SendEmail/Here is a short bit of code that I stripped out of that larger program. I had to remove quite a bit of business stuff from the code, but I do not think I messed anything up to prevent it from working. You would need to download the sendEmail program and then update all of the necessary variables. Everything is contained within a Struct for my purposes that way anything set outside of the function purposefully would work inside the function (I just rarely use Global variables...). You can choose to send the email as a regular email or send it as HTML. I ended up changing over to HTML since it affords the ability to insert quite a few standard HTML objects within the email. Note that this example also does not include showing how to set TLS to true nor does it have the username & password set. My situation did not require those, but if yours does then it is very easy to add those attributes. If you have any questions let me know here or send me a PM. Global CRLF$ : CRLF$ = chr$(13) + chr$(10) Global False : False = 0 Global True : True = 1
'Create the struct for sendEmail Struct sendEmail, senderName As ptr, _ recipientName As ptr, _ carbonCopy As ptr, _ blindCarbonCopy As ptr, _ serverIP As ptr, _ userName As ptr, _ userPassword As ptr, _ mailSubject As ptr, _ message As ptr, _ attachment As ptr, _ logFilePath As ptr, _ logFileName As ptr, _ sendEmailPath As ptr
sendEmail.sendEmailPath.struct = "Complete filepath and filename for the sendEmail.exe" 'Ex. "C:\sendEmail.exe" sendEmail.senderName.struct = "Sender_Email_Address_Here@Somewhere.com" sendEmail.userName.struct = "User_Sending_Email@Somewhere.com" sendEmail.recipientName.struct = "User1@Somewhere.com; User2@Somewhere.com" sendEmail.carbonCopy.struct = "User3@Somewhere.com; User4@Somewhere.com"
'Port 25 is typical, but you may have to change it based on the server you are using 'and how it is configured sendEmail.serverIP.struct = "IP_Address_Of_Server:25" sendEmail.logFilePath.struct = "Path to where you want to create a logfile" 'Leave blank if you do not want a logfile created sendEmail.logFileName.struct = "Your logfile name.log"
sendEmail.attachment.struct = "Complete filepath and filename of attachment"
message$ = "Here is where you add your message." + CRLF$ + _ "For a new line, add the CRLF$ as shown."
result = sendEmail("Place your email subject here!", message$, True) End
Function sendEmail(subject$, message$, isHTML) sendEmail.mailSubject.struct = chr$(34);subject$;chr$(34)
cmd$ = " -f ";Winstring(sendEmail.senderName.struct); _ " -t ";Winstring(sendEmail.recipientName.struct)
If Winstring(sendEmail.carbonCopy.struct) <> "" Then cmd$ = cmd$;" -cc ";Winstring(sendEmail.carbonCopy.struct) End If
cmd$ = cmd$;" -s ";Winstring(sendEmail.serverIP.struct); _ " -u ";Winstring(sendEmail.mailSubject.struct)
If isHTML Then cmd$ = cmd$;" -o ";chr$(34);"message-content-type=html";chr$(34) message$ = "<html><head></head><body>" + message$ + "</body></html>"
message$ = ReplaceString$(1, message$, CRLF$;"/\&", "<br>/\&", "/\", True) End If
sendEmail.message.struct = chr$(34) + message$ + chr$(34)
If Winstring(sendEmail.attachment.struct) <> "" Then cmd$ = cmd$;" -a ";chr$(34);Winstring(sendEmail.attachment.struct);chr$(34) sendEmail.attachment.struct = "" End If
cmd$ = cmd$;" -m ";Winstring(sendEmail.message.struct)
If (Winstring(sendEmail.logFilePath.struct) <> "") And (Winstring(sendEmail.logFileName.struct) <> "") Then cmd$ = cmd$;" -l ";chr$(34);Winstring(sendEmail.logFilePath.struct);"\";Winstring(sendEmail.logFileName.struct);chr$(34) End If
result = ShellExecute(0, "Open", Winstring(sendEmail.sendEmailPath.struct), cmd$, "", _SW_HIDE) sendEmail = True sendEmail.recipientName.struct = "" sendEmail.carbonCopy.struct = "" 'Clear any additional parameters here End Function
'_________________________________________________________________________________________________________________________________________________________ '_________________________________________________________________________________________________________________________________________________________
Function ShellExecute(hWnd, lpOperation$, lpFile$, lpParameters$, lpDirectory$, nShowCmd) lpOperation$ = lpOperation$ + chr$(0) : lpFile$ = lpFile$ + chr$(0) lpParameters$ = lpParameters$ + chr$(0) : lpDirectory$ = lpDirectory$ + chr$(0) CallDLL #shell32, "ShellExecuteA", hWnd As ulong, _ lpOperation$ As ptr, _ lpFile$ As ptr, _ lpParameters$ As ptr, _ lpDirectory$ As ptr, _ nShowCmd As long, _ ShellExecute As ulong End Function
'_________________________________________________________________________________________________________________________________________________________ '_________________________________________________________________________________________________________________________________________________________
Function ReplaceString$(startpos, ReplaceString$, searchfor$, replacewith$, delim$, conditional) If Not(conditional) Then Exit Function 'searchfor$/ replacewith$ can now be multiple items, but should be matched pairs 'if not then any remaing replaces will be with a NULL string searchForMe$ = searchfor$ : replacewithMe$ = replacewith$ If searchfor$ <> " " Then searchForMe$ = Word$(searchfor$, (myWord + 1), delim$) replacewithMe$ = Word$(replacewith$, (myWord + 1), delim$) End If Do While searchForMe$ <> "" 'ReplaceString$ = "" foundPosition = Instr(ReplaceString$, searchForMe$, startpos) If foundPosition Then Do While (foundPosition <> _NULL) ReplaceString$ = Left$(ReplaceString$, (foundPosition - 1)) + replacewithMe$ + _ Mid$(ReplaceString$, (foundPosition + Len(searchForMe$))) foundPosition = Instr(ReplaceString$, searchForMe$, (foundPosition + Len(replacewithMe$))) Loop End If myWord = (myWord + 1) ': string$ = ReplaceString$ searchForMe$ = Word$(searchfor$, (myWord + 1), delim$) replacewithMe$ = Word$(replacewith$, (myWord + 1), delim$) Loop End Function {:0) Brandon Parker
|
|
|
Post by tenochtitlanuk on Aug 31, 2021 16:47:49 GMT -5
sendEmail is very easy to use. Download this zip file which shows it used in a simple sub. You will need to unzip and save it to a folder for LB. Files are 'sendEmail.exe, an example file to attach, and the BASIC. Alter the lines to point to your mail server and its password, subject, message and attachment file. The chr$( 34) are quotes-signs, needed to wrap a line of text with spaces in it. Just run it. NB if the mail does not appear in your inbox, your spam filter has probably put it in the spam folder! Nigerian mail has a VERY bad reputation... Works fine for me, anyway... Caution, as before- your mail server password is going to be visible to anyone with access to the BASIC code...
|
|
curly
Full Member
Posts: 161
|
Post by curly on Sept 3, 2021 9:24:07 GMT -5
Hi Brandon and tenochtitlanuk,
Thank you very much for your help. I still have a question, as this application will be provided for running on other people's PCs and tablets, will the program I download be embedded in my programme or will the other users need to access and download a program from the web to make it work? If this is the case, I think this will pose a problem?
If that is the case, maybe you can look at the following?
The code I have attached is what I found in an old post on the forum and it looks to me as if it uses LB and one or more Windows bits? It works really well in LB4.5.1, but needs the file selected and attached by the user, and the send button clicked. I don't suppose either of you, or anyone else, knows what needs to be added to get it to attach a generic attachment from a fixed directory and send it without human intervention?
I really appreciate the help folks, Kind regards, David
'email.bas 'based on the work done by Alyce Watson in EditWorks (Thanks ' you are an inspiration to all of us!) 'Runs on LB3.x 'Modifacations by Brad Moore (blame Alyce if it don't work) ;-)
[WindowSetup] NOMAINWIN WindowWidth = 136 : WindowHeight = 73 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
[ControlSetup]
button #main.email, "Email Me",[email],UL, 10, 10, 105, 25
Open "Window Title" for Dialog as #main
print #main, "trapclose [quit]" print #main, "font ms_sans_serif 10"
hWnd = hWnd(#main)
[loop] Wait
[quit] close #main : END
[email] 'The email address is ficticious, so don't bother pressing send... file$="mailto:whoever@coolISP.com?Subject=I want to be your friend" result = ShellExecute(hWnd, file$, "") if result <= 32 then notice "Error, Address Failure!" goto [loop]
Function ShellExecute(hWnd, file$, dir$)
parameter = _SW_SHOWNORMAL ' set up for viewing lpszOp$ = "open" + Chr$(0) ' "open" or "print" lpszFile$ = file$ + Chr$(0) lpszDir$ = dir$ + Chr$(0) lpszParams$= "" + Chr$(0)
CallDLL #shell32, "ShellExecuteA", _ hWnd As ulong, _ lpszOp$ As Ptr, _ lpszFile$ As Ptr, _ lpszParams$ As Ptr, _ lpszDir$ As Ptr, _ parameter As Long, _ result As Long
ShellExecute = result
End function
|
|