Help with Secure Copy (SCP) command

Hi,

I am in the process of converting ftp transfres to SCP in my scripts.
Have some doubts with SCP command

1) currently script puts a list of ftp commands in afile and paasses the file to ftp as input

echo "user abc pwd" >inputfile
echo "ls *" >> inputfile
echo "quit" >> inputfile
ftp -n servername < inputfile > ftpoutput
 
grep -i "^A_ORD" ftpoutput > file2
grep -i "^AP_ORD" ftpoutput >> file2
 
cat file2 |
nawk ' BEGIN { print "user abc pwd";print "lcd /home/dir"} { print "asci
i"; print "get " $1 } END { print "quit" }' | ftp -n servername

I need to convert this into SCP.

scp -q  servername:"^A_ORD" /home/dir
 
scp -q servername:"AP_ORD" /home/dir

is this the correct equvalent for ftp to scp conversion. I have already installed the public keys in both the servers.

---------- Post updated at 05:54 AM ---------- Previous update was at 04:44 AM ----------

As we do not have a test environment for remote server just want to make sure the code conversion is right before porting the code to production.

It doesn't look correct. If you want to make the least needed changes to your code, it might be easier to use sftp which comes with ssh/scp too. You can leave out the user and password of course, since you have set up passwordless key authentication.

General scp syntax is same as for a simple cp or rcp; example:

scp hostA:/dir1/file*.txt ./localdir

This copies all files that match the expression from remote source to local destination.

Thanks Zaxxon..

However, the code below essentially does the same thing which you have quoted. Connect to remote server and download all files starting with A_ORD and put them in /home/dir path in local server. The FTP steps highlighted above also does the same thing but in 2 steps.

Can you please explain y u think this will not work. Thanks for your time!

 
scp -q  servername:"^A_ORD" /home/dir

scp -q servername:"AP_ORD" /home/dir

If the files are directly in the login directory of that user, the lower one will work. The upper one most probably not, because ^ looked like a regular expression and not part of the filename that might have been taken from your former grep command, which would not work as a regular expression in a file name in this case using scp.

When you say it works, then I do not understand why you ask. Also when you issue the scp manually, you'll see if it works. I am not aware if the files that will arrive on your side will be processed automatically, but you could maybe hold such a job just to check if the transfer worked.

1 Like

Thanks . I understand now.
Im facing difficultly because i dont have a test machine for remote server to check if this scp will actually work as i want it to.

And testing with the production machine is no option? Just copying a file remote by scp to your local box is no problem. As already written, you just have to take care that the files that arrived do not overwrite something important or are mixed up with other production files, as well that no automatism processes the newly arrived files.