1846870 Members
3283 Online
110256 Solutions
New Discussion

FTP Script

 
SOLVED
Go to solution
Sanjay Tailor
Frequent Advisor

FTP Script

Hello,

I have the following script to send a specific file to a specific IP. I would like to put my script file in one place and actual file to transfer is another directory. But when I tried to put in the full path of sourcefile I got an error. Can anyone help? How would I tell ftp to look in the other directory and put the file? The script runs fine when the script file and sourcefile are in the same directory. Also, I will run this fron cron, do I have to change the script to accomodate for cron?


# machine=$1
# sourcefile=$2
# destfile=$3
ftp -n -i <<-EOF
open xxx.xxx.xxx.xxx
user username passwd
binary
mput pic.jpg
quit


Thanks for your help,
Sanjay.
5 REPLIES 5
Paul Hite
Trusted Contributor

Re: FTP Script

If you do a "put /export1/images/xxx.jpg" then that path must exist on both the source and destination systems. Instead of that, put a line "cd /export1/images" (or whereever) in your script just before the line where you invoke ftp if you need to change the directory on the souse system. Or put cd line after the ftp line to change the directory on the destination system.
James R. Ferguson
Acclaimed Contributor

Re: FTP Script

Sanjay:

1. After the line for user / password, do:

$ACTION $LOCALFILE $REMOTEFILE

where ACTION is "put" or "get" and LOCALFILE is the name of the file on the host that this script is running; and REMOTEFILE is the name of the file on the server to which you are putting or getting.

2. I would use absolute paths for the LOCALFILE and REMOTEFILE. This will allow you to cd to the directory in which your script resides, pass the arguments you want for LOCALFILE & REMOTEFILE, and execute.

3. The script as you have shown should work fine under cron.

...JRF...
Sanjay Tailor
Frequent Advisor

Re: FTP Script

Hello,

Thank you for your suggestions. While offline, I looked at the FTP man page (again) and found a command called lcd which lets me change the local directory to whatever I want. I tried it and it seems to be working. I put it into the script right after I supply the username and passwd.

Sanjay.
James R. Ferguson
Acclaimed Contributor

Re: FTP Script

Hi!

Your most welcome!!! Points are always appreciated too.

...JRF...
Insu Kim
Honored Contributor
Solution

Re: FTP Script

I hope that the example shown below will help you.

# ftp -v -n < ftp.script
(Inside of ftp.script file)

open
user xxx yyy
prompt off
cd -> Change a directory on a remote system.
lcd -> Change a directory on a local system.
binary
mget filename
bye
Never say "no" first.