ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
yes, i used my own argv array which is why I thought I could use strerror() and thought posix_spawnp will give me the correct status:
SCP Return Codes
0
Operation was successful
1
General error in file copy
2
Destination is not directory, but it should be
3
Maximum symlink level exceeded
4
Connecting to host failed.
5
Connection broken
6
File does not exist
7
No permission to access file.
8
General error in sftp protocol
9
File transfer protocol mismatch
10
No file matches a given criteria
65
Host not allowed to connect
66
General error in ssh protocol
67
Key exchange failed
68
Reserved
69
MAC error
70
Compression error
71
Service not available
72
Protocol version not supported
73
Host key not verifiable
74
Connection failed
75
Disconnected by application
76
Too many connections
77
Authentication cancelled by user
78
No more authentication methods available
79
Invalid user name
Again, according to the man-page of scp, 0 is returned on success, and a number > 0 is returned on the occurrence of an error.
I do not know where you obtained the list of status values; it does not appear on the man-page for 'scp', and I have taken the effort to check on Linux, HP-UX, and a Mac. Are you on a different OS?
Again, according to the man-page of scp, 0 is returned on success, and a number > 0 is returned on the occurrence of an error.
I do not know where you obtained the list of status values; it does not appear on the man-page for 'scp', and I have taken the effort to check on Linux, HP-UX, and a Mac. Are you on a different OS?
whoops i am sorry, actually i did the same exercise as you performed and couldnt get the error status. I am using linux..i found this on google.. sorry i should have mentioned the source, my bad!! So with my implementation , you dont recommend using strerror??
whoops i am sorry, actually i did the same exercise as you performed and couldnt get the error status. I am using linux..i found this on google.. sorry i should have mentioned the source, my bad!! So with my implementation , you dont recommend using strerror??
I recommend using popen(); use it to read any output that 'scp' may return. For example:
I understand why my code doesnt work clearly after running your example. Yours works like a charm mate... thanks!! but just a thought:
I am giving a wrong scp command on purpose (this is how it would be stored internally in "cmd" per your code):
I understand why my code doesnt work clearly after running your example. Yours works like a charm mate... thanks!! but just a thought:
I am giving a wrong scp command on purpose (this is how it would be stored internally in "cmd" per your code):
This is actually giving me the print saying Transfer completed successfully!! I am wondering how..
This is the error I get when running the command on my system:
Code:
/usr/bin/scp -p -o StrictHostKeychecking=no aks@something.com:/test/tmp /tmp
ssh: Could not resolve hostname something.com: Name or service not known
If I modify the code I provided earlier to adjust the scp_src and the scp_dst, I get the following error:
Code:
Error: ssh: Could not resolve hostname something.com: Name or service not known
Quote:
Originally Posted by akshay_satish
coudl you pls explain the below 2 lines pls:
Code:
fgets(output, sizeof(output), cmd_fp);
if (strlen(output) == 0)
fgets() reads from the stream cmd_fp, up to a certain amount of characters. If there is nothing to read, then it is assumed the command (that is, scp) succeeded. This of course only works if scp is passed the -q option.
EDIT: I'm wagering that you forgot to place this at the end of your command buffer in your code: "2>&1". This directs standard-error to standard-out, thus enabling the fgets() to do its job.
Last edited by dwhitney67; 11-20-2012 at 01:50 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.