Run me without any documents to first set destination host and user-id. Then drop
files on me and they will be sent to that host via FTP.
Atul Butte
atul_butte@brown.edu
*)
global LF, CR, CRLF
property ftp_set : false
property ftp_host : ""
property ftp_user : ""
property ftp_directory : ""
property ftp_transfer_type : ""
on run
set dialog_response to (display dialog "Enter the name of the machine where you want to send files dropped on me" default answer ftp_host)
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_host to text returned of dialog_response
end if
set dialog_response to (display dialog "Enter your user–id on " & ftp_host default answer ftp_user)
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_user to text returned of dialog_response
end if
set dialog_response to (display dialog "Enter the directory on " & ftp_host & " in which to store the files, or press Return for default directory" default answer ftp_directory)
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_directory to text returned of dialog_response
end if
set dialog_response to (display dialog "Do you want these downloaded as (1) MacBinary files, (2) text files, or (3) raw data files?" default answer "1")
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_transfer_type to ((text returned of dialog_response) as integer)
end if
set ftp_set to true
end run
on open (docList)
set LF to (ASCII character of 10)
set CR to (ASCII character of 13)
set CRLF to CR & LF
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set localAddr to (tcp my address)
set localAddrList to text items of localAddr
set AppleScript's text item delimiters to {","}
set localAddrCommaString to localAddrList as string
set AppleScript's text item delimiters to oldDelimiters
if not ftp_set then
run
end if
set dialog_response to (display dialog "Enter the password for " & ftp_user & "@" & ftp_host & return & "Note: what you type is visible!" default answer "")
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_password to text returned of dialog_response
end if
set sss to (tcp connect to host ftp_host port 21)
try
readresponse(sss)
if (ftp_user ≠ "") then
tcp write stream sss data "USER " & ftp_user & return using ISO88591
readresponse(sss)
end if
if (ftp_password ≠ "") then
tcp write stream sss data "PASS " & ftp_password & return using ISO88591
readresponse(sss)
end if
if (ftp_directory ≠ "") then
tcp write stream sss data "CWD " & ftp_directory & return using ISO88591
readresponse(sss)
end if
repeat with aFile in docList
set aFile to contents of aFile
if ftp_transfer_type ≠ 2 then
tcp write stream sss data "TYPE I" & return using ISO88591
readresponse(sss)
else
tcp write stream sss data "TYPE A" & return using ISO88591
readresponse(sss)
end if
set data_stream to (tcp wait for connect)
set data_stream_status to (tcp status stream data_stream)
set portHiByte to round (local port of data_stream_status) / 256 rounding down
set portLoByte to (local port of data_stream_status) mod 256