I need to connect to a ftp server-1 from linux server-2 and copy/get a file from server-1 which follows a name pattern of FILENAME* (located on the root directory) and copy on a directory on server-2. Later, I have to use this file for ETL loading... For this I tried using as below
if ftp knows about mkdir or cd, it certainly doesnt know cp... since it uses put, get, mput, mget
alternative would be with ssh: scp
do a man of scp to see if you have it installed and look how it is used...
Should work (we get all files FILENAME* from root of source to destination on server 2 ...)
For invalid command was cp... did not say it would not work with known ftp commands...
to run the script on server2, I am now getting the following error:
Currently, FILENAME26.txt is the only file available on the server1.
So I tried to give the exact file name which is present on server1 and changed "mget" to "get" to check if this copies the file on server2 location (/directory_location_to/copy/on_server2/) this time, now the script looks like
cat ftp_test.sh
/usr/bin/ftp -n ftpsitename.com <<EOF
quote USER 12345
quote PASS 12345
get /FILENAME26.txt /directory_location_to/copy/on_server2/
EOF
i get a different error:
However, I checked on server 2 if the directory
exists or not, and it does exist... I even tried to get the file on server2 home directory, but I get the same error as above... How does the command know to put the file on the server2(since we are not mentioning about it in the code)??? any further suggestion on this???
long time since last time I wrote a script for ftp...
You have 2 other things you could do, and read also the man pages of your ftp command..., using cd and lcd lcd for local cd cd for remote cd
so your script:
/usr/bin/ftp -n ftpsitename.com <<EOF
quote USER 12345
quote PASS 12345
lcd /directory_location_to/copy/on_server2/
cd /
mget FILENAME*
EOF
But not sure I understood what you wanted in fact: Is it
bring back all files beginning by FILENAME
to
/directory_location_to/copy/on_server2/
?
(And not as I understood first : and content of /directory_location_to/copy/on_server2/...)