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?










share|improve this question
























  • 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 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















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?










share|improve this question
























  • 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 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













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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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 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
















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










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.






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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.






    share|improve this answer

























      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.






      share|improve this answer























        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 17:22









        dirkt

        16.2k21234




        16.2k21234






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Morgemoulin

            Scott Moir

            Souastre