Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- uploadFileByFTP
- -- uploads a file by FTP (non-secure/sFTP!)
- --
- -- usage:
- -- uploadFileByFTP "ftp://ftp.domain.com/" "c:\\temp\\file.ext"
- -- -- uploads to /file.ext
- -- uploadFileByFTP "ftp.domain.com" "c:\\temp\\file.ext"
- -- -- uploads to /file.ext
- -- uploadFileByFTP "ftp.domain.com/folder/" "c:\\temp\\file.ext"
- -- -- uploads to /folder/file.ext . Trailing slash is very important!
- --
- -- uploadFileByFTP "ftp.domain.com/folder/otherfile.ext" "c:\\temp\\file.ext"
- -- -- uploads file as /folder/otherfile.ext
- -- uploadFileByFTP "ftp.domain.com/folder" "c:\\temp\\file.ext"
- -- -- uploads file as /folder (filename - told you the trailing slash is very important
- --
- -- uploadFileByFTP "ftp.domain.com" "c:\\temp\\file.ext" user:"myusername" pass:"password"
- -- -- uploads file as /file.ext , logging in with given username and password
- --
- -- uploadFileByFTP "ftp.domain.com" "c:\\temp\\file.ext" err:&myVar
- -- -- uploads file as /file.ext , stores error (if any) in myVar
- --
- -- returns:
- -- true -- upload successful
- -- false -- upload failed. Pass a by-reference variable to err: to retrieve the error.
- fn uploadFileByFTP FTPpath file &err: user: pass: = (
- local FTP = dotNetObject "System.Net.WebClient"
- local pathChunks = filterString FTPpath "/"
- local FTPdomain
- if (pathChunks[1] != "ftp:") do ( insertItem "ftp:" pathChunks 1 )
- FTPdomain = pathChunks[2]
- FTP.baseAddress = "ftp://" + FTPdomain + "/"
- local FTPtarget = ""
- if (pathChunks[3] != undefined) then (
- for i = 3 to (pathChunks.count - 1) do (
- append FTPtarget (pathChunks[i] + "/" )
- )
- append FTPtarget pathChunks[pathChunks.count]
- if (FTPpath[FTPpath.count] == "/") then ( append FTPtarget ("/" + (filenameFromPath file)) )
- )
- else (
- FTPtarget = filenameFromPath file
- )
- FTP.credentials = (dotNetObject "System.Net.NetworkCredential")
- FTP.credentials.username = if (user != unsupplied) then ( user ) else ( "anonymous" )
- FTP.credentials.password = if (pass != unsupplied) then ( pass ) else ( "ano@nym.us" )
- local returnval = true
- try ( FTP.uploadFile FTPtarget file)
- catch ( returnval = false; err = getCurrentException() )
- FTP.dispose()
- return returnval
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement