PDA

View Full Version : Script to arcive and mail?


melkao
04-15-2009, 06:14 PM
Hi everyone.

Anyone knows how to create a script (or already created) that allows to create the normal file/arcive and send it via mail or ftp n a page that requires to login?

For example: i want to upload a 3d project to any ftp service (renderfarm or bakup) and i need to register to upload the file....there is a way to do this from 3d max with a script?

melkao
04-20-2009, 08:18 PM
No one?....i need help

thatoneguy
04-21-2009, 01:31 AM
DosCommand
ShellLaunch
and
HiddenDOSCommand

This is going to be a command line action not a max action.

Unless you use .net somehow.

ZeBoxx2
04-21-2009, 01:46 AM
you'll also have to write your own max file archiver, unless I missed a max file archive command outside of "max file archive" that lets you specify the filename

Kameleon
04-21-2009, 11:46 AM
Hi,
on a quick note here's the starting code:

dotnet.loadAssembly "System.Net"
dotnet.loadAssembly "System.IO"

arDir = getdir #archives
theFile = "test_upload"
theArc = #((arDir+@"\"+theFile+".max"))
theZip = maz (arDir+@"\"+theFile+".zip") theArc
theZip = (arDir+@"\"+theFile+".zip")
theRemote=@"ftp://ftp.uploads.com/"+theFile+".zip"

clsRequest = (dotnetClass "System.Net.FtpWebRequest").Create theRemote
clsRequest.Credentials = dotnetObject "System.Net.NetworkCredential" "username" "password"
--wrMethods = dotnetclass "System.Net.WebRequestMethods"
clsRequest.Method = "STOR"

bFile = (dotnetClass "System.IO.File").ReadAllBytes theZip

clsStream = clsRequest.GetRequestStream()
clsStream.Write bFile 0 bFile.Count
clsStream.Close()
clsStream.Dispose()

At this stage this only zips one file (the max file defined in theFile variable, we need to write a custom archive method like ZeBoxx said). The upload seems to be working fine.

Either way, wouldnt it be easier to archive the files using Max default archive and uploading the files with an ftp client?...

melkao
04-21-2009, 10:29 PM
Thanks guys..that was so helpfull....but iīm stuck here.

What i want to do is an automated system that creates the archive and upload the file to a ftp service...that askme for user/password, something like rebusfarm works with the "Farminizer".

MoonDoggie
04-22-2009, 07:53 PM
Kameleon,

What are you learning all of Dot NET from? I'm looking for some good .net resources, and I've looked through all of the ones in the sticky-ed thread, any others you suggest?

Kameleon
04-23-2009, 10:15 AM
Hi Colin,
There's really nothing special about it, I have a Visual Basic background and my two main resources are MSDN and lot of googling.

http://msdn.microsoft.com

Cheers and if there's anything I can help, just ask.

MoonDoggie
04-23-2009, 04:04 PM
Thanks! I'm playing around with listview right now, and it's not too hard, I just find myself trying to find methods and properties with little success...For instance figuring out how to Delete all the Listview items was challenging and with alot of guess work! How do you go about finding the props and methods for things like that?

-Colin

Kameleon
04-23-2009, 04:11 PM
Hey, I go to MSDN and I do alot of debbuging in my scripts by doing showmethods and showproperties, check out the Maxscript help for dotnet. You can even use dotnet.showconstructors "System.Windows.Forms.ListView" for example to see how to create a listview or anything you want! Cheers.

PEN
04-23-2009, 04:35 PM
Thanks! I'm playing around with listview right now, and it's not too hard, I just find myself trying to find methods and properties with little success...For instance figuring out how to Delete all the Listview items was challenging and with alot of guess work! How do you go about finding the props and methods for things like that?

-Colin

Have you seen these tutorials on my site?

http://paulneale.com/tutorials/dotNet/dotNet.htm

melkao
04-23-2009, 05:27 PM
Ok...and what about my question?

ZeBoxx2
04-23-2009, 06:54 PM
your question was answered? Unless you want somebody to provide the complete code for you, of course.

1. write a Max File archiver.
You could use max's own File > Archive, but you'll have to use UIAccessor to set the filename to exactly what you need.
Otherwise, you'll have to write your own archiver, probably using the asset tracker to get at all the bitmaps, IES files, xref'd files, etc. that you might need.

2. Upload the file to an FTP site
See Kameleon's post.

What's missing?

Edit: side > site

Kameleon
04-23-2009, 07:05 PM
I've actually written the tool but I'm struggling with a minor issue that is to encrypt the password that is saved to an INI file... I'll post something later, cheers.

Kameleon
04-23-2009, 08:57 PM
Ok...and what about my question?

Well...anyway... here's a working example:

(
dnConvert=dotnetClass "System.Convert"
dnUTF8 = dotNetObject "System.Text.UTF8Encoding"
rijn=(dotnetClass "System.Security.Cryptography.SymmetricAlgorithm").Create()
bKey=#(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2)
bIV=#(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6)

arDir = getdir #archives
theINI=arDir+@"\UAS_settings.ini"
fExists=getfilesize theINI
if fExists!=0 then
(

encText=dnConvert.FromBase64String (getINISetting theINI "UAS Settings" "Password")
memStream = dotnetObject "System.IO.MemoryStream"
cStreamMode=(dotnetClass "System.Security.Cryptography.CryptoStreamMode")
cStreamTransform=rijn.CreateDecryptor bKey bIV
cStream=dotnetObject "System.Security.Cryptography.CryptoStream" memStream cStreamTransform cStreamMode.Write
cStream.Write encText 0 encText.Count
cStream.FlushFinalBlock()
cipherBytes=memStream.ToArray()
memStream.Close()
cStream.Close()

dectext=dnUTF8.GetString cipherBytes

theFTP=getINISetting theINI "UAS Settings" "FTP"
theUsername=getINISetting theINI "UAS Settings" "Username"
thePassword=decText
)
else
(
theFTP=@"ftp://ftp.google.com/"
theUsername="anonymous"
thePassword="password"
)

rollout rUpload "Upload"
(
button btn_Archive "Archive" across:2 align:#left
button btn_Upload "Upload" align:#right
progressbar pb_Upload
button btn_site "?" align:#center

local webClient = dotnetObject "System.Net.WebClient"

fn UploadProgressChanged sender args =
(
pb_Upload.value=args.ProgressPercentage
)

fn UploadFileCompleted sender args =
(
if args.Error==undefined then print "Upload finished" else print "An error as occurred"
)

on rUpload open do
(
dotnet.addEventHandler webClient "UploadProgressChanged" UploadProgressChanged
dotnet.addEventHandler webClient "UploadFileCompleted" UploadFileCompleted
)
on btn_Archive pressed do
(
max file archive
)
on btn_Upload pressed do
(
theFile = getFilenameFile maxFilename
theZip = (arDir+@"\"+theFile+".zip")
fExists=getfilesize theZip
if fExists!=0 then
(
print "Upload started"
theRemote=theFTP+theFile+".zip"
theUri=dotnetObject "System.Uri" theRemote
webClient.Credentials = dotnetObject "System.Net.NetworkCredential" theUsername thePassword
webClient.UploadFileAsync theUri theZip
) else print "Upload aborted"
)

on btn_site pressed do
(
process=dotnetclass "System.Diagnostics.Process"
process.start "http://www.dimensao3.com/al"
)
)

rollout sFTP "Setup FTP"
(
edittext txt_host "Host:" text:@"ftp://ftp.google.com" labelOnTop:true
edittext txt_username"Username:" text:"anonymous" labelOnTop:true
edittext txt_password "Password:" text:"password" labelOnTop:true
button btn_save "Save settings"

on btn_save pressed do
(

encText=dnUTF8.GetBytes txt_password.text
memStream = dotnetObject "System.IO.MemoryStream"
cStreamMode=(dotnetClass "System.Security.Cryptography.CryptoStreamMode")
cStreamTransform=rijn.CreateEncryptor bKey bIV
cStream=dotnetObject "System.Security.Cryptography.CryptoStream" memStream cStreamTransform cStreamMode.Write
cStream.Write encText 0 encText.Count
cStream.FlushFinalBlock()
cipherBytes=memStream.ToArray()
memStream.Close()
cStream.Close()

enctext=dnConvert.ToBase64String cipherBytes

deleteFile theINI
setINISetting theINI "UAS Settings" "FTP" theFTP
setINISetting theINI "UAS Settings" "Username" theUsername
setINISetting theINI "UAS Settings" "Password" encText
)

on sFTP open do
(
txt_host.text=theFTP
txt_username.text=theUsername
txt_password.text=thePassword
)

on txt_host changed eText do
(
theFTP=eText
)
on txt_username changed eText do
(
theUsername=eText
)
on txt_password changed eText do
(
thePassword=eText
)
)

mainFloat=newRolloutFloater "Upload Archived Scenes" 300 290
addRollout rUpload mainFloat
addRollout sFTP mainFloat
)

MoonDoggie
04-24-2009, 04:16 PM
Thanks PEN, I for some reason hadn't seen those! Thanks for the resource, and thanks Kameleon.

Kameleon
04-29-2009, 11:33 AM
Hey guys, here's an update with support for FTP presets :) Cheers.

melkao
04-29-2009, 05:03 PM
Kameleon: ok...i just say...wow!...thanks man...i didnīt expected that. thats so helpful...

ZeBoxx2: well yes..but i am not good with max script and i donīt know much about programing. I was asking for some tutorial, or guide to help me do it. iīm just a noob on it jejejeje...but thanks for your help.

Kameleon
04-29-2009, 05:31 PM
Hey Carlos, no problem. Just download the latest file I've attached so you can have multiple FTP's configured, and remember not to change the filename when archiving or it will error. Cheers.

melkao
04-29-2009, 05:37 PM
Thanks a lot...but i just try it...and is not uploading...and another question...how can i to customize?....for example..if i want to put an image or logo..or icon.

Again...thanks for your help!

CGTalk Moderation
04-29-2009, 05:37 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.