Web Hosting Talk







View Full Version : automate FTP


tymonhall
04-04-2001, 06:31 PM
I am trying to get a file to be copied from one server to another thru ftp do anyone know how to do this?

jtan15
04-04-2001, 07:25 PM
Have you looked into SCP?

tymonhall
04-04-2001, 07:37 PM
Never heard of it

jtan15
04-04-2001, 10:53 PM
You actually don't even need to use SCP. You can setup SSH to transfer files from server to server. Here's an example line of code that would do the trick:

"command to execute" | ssh -l username -i identity -c blowfish HOSTNAME

What is it that you want transferred over? If you wanted to tar up a directory every night and send it to another server, you could run the tar command and simply pipe it to the SSH connection. You would need to create your identity using the ssh-keygen program.

What exactly is it that you want to do?

pyng
04-05-2001, 10:22 AM
Originally posted by Vincent Paglione
"command to execute" | ssh -l username -i identity -c blowfish HOSTNAME


When you do something like this, how do you get around the need to enter your passphrase, unless you have .shosts and RSARhostsAuthentication enabled or something...

The above command probably wouldn't do anything very useful, though, unless the command to execute actually spits out shell commands. Yes, I know that was just a sample command :)

tymonhall
04-05-2001, 12:27 PM
What I am trying to transfer is a simple text file. I am looking for the quickest way of doing this.

Justin S
04-05-2001, 01:02 PM
Type in the following:


ftp ftp.domain.com


Then it'll ask for your username and password. After that's done, 'cd' to the directory where the text file is. Then type the following:


get textfile.txt


Hope that helps!

jtan15
04-05-2001, 01:06 PM
Originally posted by pyng
Originally posted by Vincent Paglione
"command to execute" | ssh -l username -i identity -c blowfish HOSTNAME


When you do something like this, how do you get around the need to enter your passphrase, unless you have .shosts and RSARhostsAuthentication enabled or something...

The above command probably wouldn't do anything very useful, though, unless the command to execute actually spits out shell commands. Yes, I know that was just a sample command :)

The "-i file" command asks for your identity file which is for your RSA authentication.

Using this method will also allow you to transfer files.

tymonhall
04-05-2001, 04:15 PM
All of this you can automate?

tymonhall
04-05-2001, 04:24 PM
Can someone give me the command line step by step on what I need to do to transfer the files? I've tried ssh but cant figure this out. I need this process to be automated so the only thing I would need to do is enter everything in the command line.

pyng
04-06-2001, 04:40 AM
A few possibilities come to mind.

1. You could use ftp. I think you can automate the authentication steps using .netrc - see man 5 netrc

2. You could use ftp, but script the entire ftp session using Expect.

3. You could use ncftp (or one of the other ftp clients can save your authentication info) to push the file out or pull it in. Or you could even use wget -i inputfile and put ftp://user:passwor@source.host.com/path/to/file in the file inputfile.

4. You could use scp/ssh. I _believe_ that vincent's suggestion above requires you to type in your ssh passphrase, so doesn't automate easily. It's also probably considerably more secure than the above. Suppose you want to copy a file from "a.foo.com" to "b.bar.com". First go to b.bar.com, type ssh -l username a.foo.com and make sure you get a's hostkey saved in your known hosts file. Go back to b and put the line a.foo.com in the file ~/.shosts, making sure that that file is mode 0600. Finally, go to a, and type "scp -o rhostsrsaauthentication=yes -o protocol=1 file.to.copy b.bar.com:path/to/copy/file/to". Note that I'm assuming you have the same username on both sides, and that b has not denied use of ssh protocol 1 or rhostsrsaauthentication (both of which i deny on my servers, incidentally).

I'm sure there are many other ways of automating the file transfer, but these are probably sufficient. There may also be simpler ways of doing automated scp - somebody please clue me in if so.


What you can do is to put the host with the file you want to copy in the file ~/.shosts on the host you want the file to end up.