I'm trying to copy a file from a remote server B to a remote server A. My Elixir application is on server A. I'm doing this:
a1 = System.cmd("scp", ["[serverB.....]", "/opt/folder1/"])
# => Permission denied
# {"", 1}
a2 = System.cmd("scp", ["serverB.....]", "/home/my_user"])
# => Connection to serverB closed by remote host.
# lost connection
# {"", 1}
In the 1st case I receive nothing but Permission Denied.
In the 2nd case I do receive a file, that's good, but why does it look like it's failed?
My goal is to get the first to work because I want file to be downloaded directly to "/opt/folder1/". Preferably.
How can I do that? Is it possible via scp? Or should I download it to my home directory first?
And why does it kind of fail in the 2nd case , what's wrong?
Also, maybe I should instead use rsync
to avoid the permission issues?
update:
I've given the permissions to the folder "/opt/folder1/"
sudo chmod 775
but the error hasn't gone away.
update2
I've given the permissions 777. It kinds of works -- the file is downloaded. But the return result is still this:
Connection to bb.bb.bb.bb closed by remote host.
lost connection
{"", 1}
Why is that? 1 implies "error" doesn't it? Let alone "lost connection".
Login to the serverB
with plain old good ssh
and execute:
sudo chown -R my_user /opt/folder1/
or (if and only you perfectly understand the consequences):
sudo chmod a+xw /opt/folder1/
Logout from remote. Now you should be able to execute System.cmd/3
successfully.
In general, the format of the scp
command would be:
scp SOURCE_FILE TARGET_USER@TARGET_HOST:TARGET_DIR
So you'd probably better execute:
System.cmd("scp", ["my_local_file", "my_user@bb.bb.bb.bb:/opt/folder1/"])
That way you should receive {"", 0}
response from System.cmd/3
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.