• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Another Shell Script question ftp
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another Shell Script question ftp


  • Subject: Re: Another Shell Script question ftp
  • From: deivy petrescu <email@hidden>
  • Date: Fri, 10 Feb 2006 23:02:44 -0500


On Feb 10, 2006, at 14:24, Stockly, Ed wrote:

 Hi again,

You know I think it's taking my longer to learn shell scripting because I'm trying to do it through appleScript's do shell script command.

One of the the problems I've found is that I can do workable version in terminal that doesn't work via do shell script.

So, here's the solution I'm ready to use. Hope there's nothing in there to bite me!

ES
set errLog to {}
tell application "Finder" to set fileName to the name of alias fileToMove
set localFile to quoted form of POSIX path of alias fileToMove
set ftpShellScript to "ftp -d -v -u ftp://"; & remoteUserid & ":" & remotePassword & "@" & remoteServer & ":21" & remotePath & fileName & " " & localFile
try
tell application "Terminal"
do script ftpShellScript
delay 3
set shellScriptLog to contents of window 1
end tell
if shellScriptLog contains "226 Transfer complete." then
tell application "Finder"
delete alias fileToMove
empty trash
end tell
else
set the end of errLog to {"File Name: " & fileName, "Shell script:", ftpShellScript, "ErrorMessage: ", errText, " Error code: " & errNum, " User Id: " & remoteUserid, " User password: " & remotePassword, " Remote server: " & remoteServer, " Remote path: " & RemoteDirPath, " Remote directory: " & remoteDirectory, " Error directory: " & errorDirectory, " Shell Script log: " & shellScriptLog} as string
try
tell application "Finder"

move alias fileToMove to erro!
rDirectory
delete fileToMoveAlias
empty trash
end tell
end try
end if
end try




Ed Stockly
Los Angeles Times
Assistant Editor TV Times


Ed,
If you feel your way is solving your problem, by all means stick with it.
However, there is a lot you are not using and you can do so much more with ftp.


First, I do not know how many ftp sites you have to log in to, but no matter how many, use ".netrc" .
This is a file that contains, at least, all the ftp sites you deal with, their userids and passwords.
That is, using your favorite (ASCII) text editor you put the following line for each of the ftp sites you are going to log in:


machine "your.domain.com" login "yourUserid" password "yourPasswword" ( macdef init cd "public_html" )


where you should not use quotes and each word between quotes is kinda self explanatory (macdef is for later).
Create a line for each machine.
Now, if you in your terminal window type ftp your.domain.com you automatically get logged into the account *and* if you put the macdef init "cd public_html" you are automatically moved to the remote directory public_html.
So if you generally go to the same directory this saves a lot of typing.


Now, say you normally have your files to upload in your document folders. Say they are in the ToUpload folder.

You can create an alias (Unix alias, not mac alias) in whatever shell you work. I work in tcsh, the default MacOS is bash and the best, according to a guy I consider a guru, is the zsh.
Well, in my tcsh shell this alias is :




alias fydc   'cd ~/Documents/ToUpload/; ftp your.domain.com'

And in my case (tcsh) it is placed on:
~/Library/init/tcsh/aliases.mine

After that, you type in your terminal

[powermacg4:~]% fydc

and, you change the local current directory to ~/Documents/ ToUpload/, log in your ftp site and change the directory to public_html.

4 letters!

I generally keep a local folder with the same structure of the ftp site.
Once I am in, to script the exchange of files is very easy. And since is now pure AppleScript, you can be really sophisticated.


So, here is an example of a simple script, it goes thru local folders and puts the new version on the remote folders of the same name:

<script>
set theScript to "fydc --- this is saved in my alias file
cd todasasnotas/Grades136/ -- I could have used public_html/ todasasnotas/
-- in macdef init above, but I left it as an illustration
lcd todasasnotas/Grades136/ -- lcd changes the directory locally
prompt -- turns prompt off, great if you are transferring many files
mput *.html -- puts any file of the form name.html into the remote machine
cd ../Grades299/ -- changes to a different remote directory (mirrored)
lcd ../Grades299/ -- changes to a different local directory
mput *.html
cd ../Grades352/
lcd ../Grades352/
mput *.html
bye" -- ends the ftp session.


tell application "Terminal"
	activate
	repeat with l from 1 to count of windows
		if window l is not busy then
			do script theScript in window l
			exit repeat
		end if
	end repeat
end tell

<script>


Notice that, since theScript is just text, you can add a list of files using Applescript, and work with older or newer files if you will.


I transfer a whole site sometimes, and the process is painless. Some of the transfer above are for about hundred files and it is done in a cinch.

The only issue I have with your script is, I'd trash things only after I've seen that everything is correct. I'd wait a bit before trashing. GB is cheap today!

Deivy



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >RE: Another Shell Script question ftp (From: "Stockly, Ed" <email@hidden>)

  • Prev by Date: Re: Dealing with Sliders...
  • Next by Date: Re: Applescript-users Digest, Vol 3, Issue 86
  • Previous by thread: RE: Another Shell Script question ftp
  • Next by thread: Re: Another Shell Script question ftp
  • Index(es):
    • Date
    • Thread