Help with Secure Copy (SCP) command

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Secure Copy (SCP) command
# 1  
Old 09-14-2011
Help with Secure Copy (SCP) command


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.
# 2  
Old 09-14-2011
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.
# 3  
Old 09-14-2011
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

# 4  
Old 09-14-2011
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.
This User Gave Thanks to zaxxon For This Post:
# 5  
Old 09-14-2011
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.
# 6  
Old 09-14-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Secure Copy - File Transfer between 2 server

Using RCP command we can transfer file from one server to another server. While transferring we can rename the file also e.g. File name = FILE123.txt (lying on Source server = oldserver) Target Server Name = newyour Renamed File = FILE456.txt rcp FILE123.txt newyour:./FILE456.txt... (1 Reply)
Discussion started by: Pash
1 Replies

2. UNIX for Advanced & Expert Users

Secure Copy, scp

Is there a way we can avoid asking of password when we transfer file from one Unix server to another server using SCP command. Or Is is possible that the batch file in unix in which I am giving the SCP command takes the password and transfer the files automatically without me typing the... (1 Reply)
Discussion started by: Pash
1 Replies

3. UNIX for Dummies Questions & Answers

directory copy with scp

I need to copy all files and directories with scp, but seems I am missing something? /usr/bin/scp -p /custscripts/* rmprod2:/custscripts doesn't copy directories and files under them. Please advise. (1 Reply)
Discussion started by: Daniel Gate
1 Replies

4. UNIX for Dummies Questions & Answers

Secure copy help

I want to use scp in a script and have two questions: 1. Is there a way to use password in script, so script does not halt and ask for my password for remote box half way through? 2. The code below copies the file to my home directory on the remote server. How can I copy "file" to the same... (3 Replies)
Discussion started by: chrisjones
3 Replies

5. Shell Programming and Scripting

SCP copy

I want to copy all the files and subdirectory from a server. I tried scp pritish@ipaddress:/home/pritish -r $PWD it copies all the files but not the directory, Can any one help me. I want to copy files as well as subdirectory from a server directory Note: Use CODE-tags when... (2 Replies)
Discussion started by:
2 Replies

6. UNIX for Dummies Questions & Answers

SCP -r from Secure FTP site

Hi all, My problem is simple. I would like to download the contents of a directory on an ftp site. I can access the site through windows, but there are many files and it would be too tedious to click and download each file. Thus, I am trying to use scp -r... (5 Replies)
Discussion started by: cpabrego
5 Replies

7. Solaris

Secure method - get files - no ssh/scp

I have two servers. server 1 - secure server running ssh only on solaris 9. I can installed whatever I need here as long as its reasonably secure server 2 - running telnet (no ssh/scp installed) - I cannot change much on this server and cannot install much.. I need to pull some files from... (3 Replies)
Discussion started by: frustrated1
3 Replies

8. UNIX for Dummies Questions & Answers

SCP - Secure copy with Certificates exchange.

Will an scp command always copy the files in an encrypted mode? After trying this, I have got message Host Key not found in the database. & Unable to write host key in my user directory. Please anyone has an idea, how we can have secure copy with certificates exchanged successfully? (0 Replies)
Discussion started by: videsh77
0 Replies

9. Shell Programming and Scripting

how to use SCP (secure copy) in UNIX

i have to transfer a file from one server to another. say, my script is running on server 'A' and one file has to be transferred from server 'A' to server 'B' using SCP. i am using it as: sourceserverA> scp -P <port> userid@serverBhostname:/put/this/here <sourcefile path> but it is giving... (1 Reply)
Discussion started by: dharmesht
1 Replies

10. UNIX for Dummies Questions & Answers

looking for a secure copy program (scp)

Hi could someone tell me where to find a secure copy prog. for unix and windows thnx a lot helios (4 Replies)
Discussion started by: helios
4 Replies
Login or Register to Ask a Question