Transfer files from Virtualbox guest to host in script with smbclient
up vote
1
down vote
favorite
I'm trying to develop a script that will run on a CentOS 7 machine, but for now I am developing it in a Virtualbox instance (also CentOS 7). The script will be handling several tasks, but the part I'm having trouble with is sending hundreds of large files to a Windows machine (which for now is my pc, or the Virtualbox host).
Two issues:
A) Sending the files to host.
Current attempt looks like:
find "${FILES_DIR}" -print0 | while read -d $'' file
do
if [ ${file: -4} == ".zip" ]
then
smbclient //${WINDOWS_IP}/${WINDOWS_DIR} -U ${WINDOWS_USERNAME}%${WINDOWS_PASSWORD} -c "put ${file}"
fi
done
Where WINDOWS_IP is enp0s3.inet, WINDOWS_DIR is a shared folder on host. Problem is I am constantly getting connection refused errors, and I don't know where to go from here.
B) Confirming file was transferred successfully
Does smbclient return anything I can use to check if the file was transferred successfully?
linux shell-script centos virtualbox samba
add a comment |
up vote
1
down vote
favorite
I'm trying to develop a script that will run on a CentOS 7 machine, but for now I am developing it in a Virtualbox instance (also CentOS 7). The script will be handling several tasks, but the part I'm having trouble with is sending hundreds of large files to a Windows machine (which for now is my pc, or the Virtualbox host).
Two issues:
A) Sending the files to host.
Current attempt looks like:
find "${FILES_DIR}" -print0 | while read -d $'' file
do
if [ ${file: -4} == ".zip" ]
then
smbclient //${WINDOWS_IP}/${WINDOWS_DIR} -U ${WINDOWS_USERNAME}%${WINDOWS_PASSWORD} -c "put ${file}"
fi
done
Where WINDOWS_IP is enp0s3.inet, WINDOWS_DIR is a shared folder on host. Problem is I am constantly getting connection refused errors, and I don't know where to go from here.
B) Confirming file was transferred successfully
Does smbclient return anything I can use to check if the file was transferred successfully?
linux shell-script centos virtualbox samba
What about using shared folders instead?
– mdpc
Nov 21 at 17:36
@mdpc Keeping in mind that the use of Virtualbox is only for some local development, I want to keep this script as close as possible to what will run in production. I should also mention I won't have control over system settings or installed packages on the future CentOS machine.
– Bott0610
Nov 21 at 17:44
1
What happens if you manually do the samesmbclient
call for a single file? Is the failure consistent, or does it only happen for certain files? Or maybe even sometimes for a single file, and sometimes not? Did you check the return code ofsmbclient
when a failure happens?
– dirkt
Nov 22 at 8:12
Don't forget that the${WINDOWS_IP}
isn't necessarily the IP/DNS hostname/ip combo but is instead the Netbios name. Check the man page for theservicename
option ofsmbclient
for info. Or, use the actual IP address. Also, connectivity may depend on what method of virtualbox networking you are using. To get as close as you can to "real" I'd use Bridged, or you could virtualize windows and use host-only or internal-only or "nat network" (not plain "nat").
– ivanivan
Nov 22 at 17:31
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to develop a script that will run on a CentOS 7 machine, but for now I am developing it in a Virtualbox instance (also CentOS 7). The script will be handling several tasks, but the part I'm having trouble with is sending hundreds of large files to a Windows machine (which for now is my pc, or the Virtualbox host).
Two issues:
A) Sending the files to host.
Current attempt looks like:
find "${FILES_DIR}" -print0 | while read -d $'' file
do
if [ ${file: -4} == ".zip" ]
then
smbclient //${WINDOWS_IP}/${WINDOWS_DIR} -U ${WINDOWS_USERNAME}%${WINDOWS_PASSWORD} -c "put ${file}"
fi
done
Where WINDOWS_IP is enp0s3.inet, WINDOWS_DIR is a shared folder on host. Problem is I am constantly getting connection refused errors, and I don't know where to go from here.
B) Confirming file was transferred successfully
Does smbclient return anything I can use to check if the file was transferred successfully?
linux shell-script centos virtualbox samba
I'm trying to develop a script that will run on a CentOS 7 machine, but for now I am developing it in a Virtualbox instance (also CentOS 7). The script will be handling several tasks, but the part I'm having trouble with is sending hundreds of large files to a Windows machine (which for now is my pc, or the Virtualbox host).
Two issues:
A) Sending the files to host.
Current attempt looks like:
find "${FILES_DIR}" -print0 | while read -d $'' file
do
if [ ${file: -4} == ".zip" ]
then
smbclient //${WINDOWS_IP}/${WINDOWS_DIR} -U ${WINDOWS_USERNAME}%${WINDOWS_PASSWORD} -c "put ${file}"
fi
done
Where WINDOWS_IP is enp0s3.inet, WINDOWS_DIR is a shared folder on host. Problem is I am constantly getting connection refused errors, and I don't know where to go from here.
B) Confirming file was transferred successfully
Does smbclient return anything I can use to check if the file was transferred successfully?
linux shell-script centos virtualbox samba
linux shell-script centos virtualbox samba
edited Nov 21 at 17:02
asked Nov 21 at 16:55
Bott0610
1533
1533
What about using shared folders instead?
– mdpc
Nov 21 at 17:36
@mdpc Keeping in mind that the use of Virtualbox is only for some local development, I want to keep this script as close as possible to what will run in production. I should also mention I won't have control over system settings or installed packages on the future CentOS machine.
– Bott0610
Nov 21 at 17:44
1
What happens if you manually do the samesmbclient
call for a single file? Is the failure consistent, or does it only happen for certain files? Or maybe even sometimes for a single file, and sometimes not? Did you check the return code ofsmbclient
when a failure happens?
– dirkt
Nov 22 at 8:12
Don't forget that the${WINDOWS_IP}
isn't necessarily the IP/DNS hostname/ip combo but is instead the Netbios name. Check the man page for theservicename
option ofsmbclient
for info. Or, use the actual IP address. Also, connectivity may depend on what method of virtualbox networking you are using. To get as close as you can to "real" I'd use Bridged, or you could virtualize windows and use host-only or internal-only or "nat network" (not plain "nat").
– ivanivan
Nov 22 at 17:31
add a comment |
What about using shared folders instead?
– mdpc
Nov 21 at 17:36
@mdpc Keeping in mind that the use of Virtualbox is only for some local development, I want to keep this script as close as possible to what will run in production. I should also mention I won't have control over system settings or installed packages on the future CentOS machine.
– Bott0610
Nov 21 at 17:44
1
What happens if you manually do the samesmbclient
call for a single file? Is the failure consistent, or does it only happen for certain files? Or maybe even sometimes for a single file, and sometimes not? Did you check the return code ofsmbclient
when a failure happens?
– dirkt
Nov 22 at 8:12
Don't forget that the${WINDOWS_IP}
isn't necessarily the IP/DNS hostname/ip combo but is instead the Netbios name. Check the man page for theservicename
option ofsmbclient
for info. Or, use the actual IP address. Also, connectivity may depend on what method of virtualbox networking you are using. To get as close as you can to "real" I'd use Bridged, or you could virtualize windows and use host-only or internal-only or "nat network" (not plain "nat").
– ivanivan
Nov 22 at 17:31
What about using shared folders instead?
– mdpc
Nov 21 at 17:36
What about using shared folders instead?
– mdpc
Nov 21 at 17:36
@mdpc Keeping in mind that the use of Virtualbox is only for some local development, I want to keep this script as close as possible to what will run in production. I should also mention I won't have control over system settings or installed packages on the future CentOS machine.
– Bott0610
Nov 21 at 17:44
@mdpc Keeping in mind that the use of Virtualbox is only for some local development, I want to keep this script as close as possible to what will run in production. I should also mention I won't have control over system settings or installed packages on the future CentOS machine.
– Bott0610
Nov 21 at 17:44
1
1
What happens if you manually do the same
smbclient
call for a single file? Is the failure consistent, or does it only happen for certain files? Or maybe even sometimes for a single file, and sometimes not? Did you check the return code of smbclient
when a failure happens?– dirkt
Nov 22 at 8:12
What happens if you manually do the same
smbclient
call for a single file? Is the failure consistent, or does it only happen for certain files? Or maybe even sometimes for a single file, and sometimes not? Did you check the return code of smbclient
when a failure happens?– dirkt
Nov 22 at 8:12
Don't forget that the
${WINDOWS_IP}
isn't necessarily the IP/DNS hostname/ip combo but is instead the Netbios name. Check the man page for the servicename
option of smbclient
for info. Or, use the actual IP address. Also, connectivity may depend on what method of virtualbox networking you are using. To get as close as you can to "real" I'd use Bridged, or you could virtualize windows and use host-only or internal-only or "nat network" (not plain "nat").– ivanivan
Nov 22 at 17:31
Don't forget that the
${WINDOWS_IP}
isn't necessarily the IP/DNS hostname/ip combo but is instead the Netbios name. Check the man page for the servicename
option of smbclient
for info. Or, use the actual IP address. Also, connectivity may depend on what method of virtualbox networking you are using. To get as close as you can to "real" I'd use Bridged, or you could virtualize windows and use host-only or internal-only or "nat network" (not plain "nat").– ivanivan
Nov 22 at 17:31
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
As for (B), my smbclient
does return an exit code at least for some errors. You can use $?
in the shell to get the exit code of the last command. An exit code of zero means "ok", non-zero is an error, for the error I provoked the exit code was 1 (but other exit codes are possible, and not all errors might set the exit code).
The "connection refused" error in mention in (A) may have many reasons, it'll difficult to debug this by Q&A. At least provide some information under what circumstances the error happens or doesn't happen, if ping
to the remote machine works, if you checked the firewall settings, etc.
And BTW, you can also pipe commands into smbclient
, as in
echo "put ${file}" | smbclient "//${WINDOWS_IP}/${WINDOWS_DIR}" -U "${WINDOWS_USERNAME}%${WINDOWS_PASSWORD}"
This may or may not help with transferring a large number of files, by avoiding making a new connection each time, if this fails randomly.
And please consider escaping everything properly (I added the quotation marks). We don't know the real values you use, and bad escaping may mangle the host, user or password, and may be the reason for the failure.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
As for (B), my smbclient
does return an exit code at least for some errors. You can use $?
in the shell to get the exit code of the last command. An exit code of zero means "ok", non-zero is an error, for the error I provoked the exit code was 1 (but other exit codes are possible, and not all errors might set the exit code).
The "connection refused" error in mention in (A) may have many reasons, it'll difficult to debug this by Q&A. At least provide some information under what circumstances the error happens or doesn't happen, if ping
to the remote machine works, if you checked the firewall settings, etc.
And BTW, you can also pipe commands into smbclient
, as in
echo "put ${file}" | smbclient "//${WINDOWS_IP}/${WINDOWS_DIR}" -U "${WINDOWS_USERNAME}%${WINDOWS_PASSWORD}"
This may or may not help with transferring a large number of files, by avoiding making a new connection each time, if this fails randomly.
And please consider escaping everything properly (I added the quotation marks). We don't know the real values you use, and bad escaping may mangle the host, user or password, and may be the reason for the failure.
add a comment |
up vote
0
down vote
As for (B), my smbclient
does return an exit code at least for some errors. You can use $?
in the shell to get the exit code of the last command. An exit code of zero means "ok", non-zero is an error, for the error I provoked the exit code was 1 (but other exit codes are possible, and not all errors might set the exit code).
The "connection refused" error in mention in (A) may have many reasons, it'll difficult to debug this by Q&A. At least provide some information under what circumstances the error happens or doesn't happen, if ping
to the remote machine works, if you checked the firewall settings, etc.
And BTW, you can also pipe commands into smbclient
, as in
echo "put ${file}" | smbclient "//${WINDOWS_IP}/${WINDOWS_DIR}" -U "${WINDOWS_USERNAME}%${WINDOWS_PASSWORD}"
This may or may not help with transferring a large number of files, by avoiding making a new connection each time, if this fails randomly.
And please consider escaping everything properly (I added the quotation marks). We don't know the real values you use, and bad escaping may mangle the host, user or password, and may be the reason for the failure.
add a comment |
up vote
0
down vote
up vote
0
down vote
As for (B), my smbclient
does return an exit code at least for some errors. You can use $?
in the shell to get the exit code of the last command. An exit code of zero means "ok", non-zero is an error, for the error I provoked the exit code was 1 (but other exit codes are possible, and not all errors might set the exit code).
The "connection refused" error in mention in (A) may have many reasons, it'll difficult to debug this by Q&A. At least provide some information under what circumstances the error happens or doesn't happen, if ping
to the remote machine works, if you checked the firewall settings, etc.
And BTW, you can also pipe commands into smbclient
, as in
echo "put ${file}" | smbclient "//${WINDOWS_IP}/${WINDOWS_DIR}" -U "${WINDOWS_USERNAME}%${WINDOWS_PASSWORD}"
This may or may not help with transferring a large number of files, by avoiding making a new connection each time, if this fails randomly.
And please consider escaping everything properly (I added the quotation marks). We don't know the real values you use, and bad escaping may mangle the host, user or password, and may be the reason for the failure.
As for (B), my smbclient
does return an exit code at least for some errors. You can use $?
in the shell to get the exit code of the last command. An exit code of zero means "ok", non-zero is an error, for the error I provoked the exit code was 1 (but other exit codes are possible, and not all errors might set the exit code).
The "connection refused" error in mention in (A) may have many reasons, it'll difficult to debug this by Q&A. At least provide some information under what circumstances the error happens or doesn't happen, if ping
to the remote machine works, if you checked the firewall settings, etc.
And BTW, you can also pipe commands into smbclient
, as in
echo "put ${file}" | smbclient "//${WINDOWS_IP}/${WINDOWS_DIR}" -U "${WINDOWS_USERNAME}%${WINDOWS_PASSWORD}"
This may or may not help with transferring a large number of files, by avoiding making a new connection each time, if this fails randomly.
And please consider escaping everything properly (I added the quotation marks). We don't know the real values you use, and bad escaping may mangle the host, user or password, and may be the reason for the failure.
answered Nov 22 at 17:22
dirkt
16.2k21234
16.2k21234
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483252%2ftransfer-files-from-virtualbox-guest-to-host-in-script-with-smbclient%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What about using shared folders instead?
– mdpc
Nov 21 at 17:36
@mdpc Keeping in mind that the use of Virtualbox is only for some local development, I want to keep this script as close as possible to what will run in production. I should also mention I won't have control over system settings or installed packages on the future CentOS machine.
– Bott0610
Nov 21 at 17:44
1
What happens if you manually do the same
smbclient
call for a single file? Is the failure consistent, or does it only happen for certain files? Or maybe even sometimes for a single file, and sometimes not? Did you check the return code ofsmbclient
when a failure happens?– dirkt
Nov 22 at 8:12
Don't forget that the
${WINDOWS_IP}
isn't necessarily the IP/DNS hostname/ip combo but is instead the Netbios name. Check the man page for theservicename
option ofsmbclient
for info. Or, use the actual IP address. Also, connectivity may depend on what method of virtualbox networking you are using. To get as close as you can to "real" I'd use Bridged, or you could virtualize windows and use host-only or internal-only or "nat network" (not plain "nat").– ivanivan
Nov 22 at 17:31