Checking ftp return codes from Unix script












3















I am currently creating an overnight job that calls a Unix script which in turn creates and transfers a file using ftp. I would like to check all possible return codes. The man page for ftp doesn't list return codes. Does anyone know where to find a list? Anyone with experience with this? We have other scripts that grep for certain return strings in the log, and they send an email when in error. However, they often miss unanticipated codes.
I am then putting the reason into the log and the email.










share|improve this question

























  • Thanks guys, as you can probably tell, my unix scripting is not that far along. I'm basically working from other scripts by people that used to work here. However, I'd like to make it more bulletproof than what I've found so far. I appreciate all answers so far.

    – Glenn Wark
    Sep 26 '08 at 15:49











  • Basically my code so far is as follows: echo " open $ftpip pwd binary lcd /out cd /in mput $datafile quit"|ftp -iv > $ftpreturn The -v option looks like what I need. But the $ftpreturn variable is blank. The file isn't getting ftp'd and is failing silently. What am I missing?

    – Glenn Wark
    Sep 26 '08 at 15:51
















3















I am currently creating an overnight job that calls a Unix script which in turn creates and transfers a file using ftp. I would like to check all possible return codes. The man page for ftp doesn't list return codes. Does anyone know where to find a list? Anyone with experience with this? We have other scripts that grep for certain return strings in the log, and they send an email when in error. However, they often miss unanticipated codes.
I am then putting the reason into the log and the email.










share|improve this question

























  • Thanks guys, as you can probably tell, my unix scripting is not that far along. I'm basically working from other scripts by people that used to work here. However, I'd like to make it more bulletproof than what I've found so far. I appreciate all answers so far.

    – Glenn Wark
    Sep 26 '08 at 15:49











  • Basically my code so far is as follows: echo " open $ftpip pwd binary lcd /out cd /in mput $datafile quit"|ftp -iv > $ftpreturn The -v option looks like what I need. But the $ftpreturn variable is blank. The file isn't getting ftp'd and is failing silently. What am I missing?

    – Glenn Wark
    Sep 26 '08 at 15:51














3












3








3


1






I am currently creating an overnight job that calls a Unix script which in turn creates and transfers a file using ftp. I would like to check all possible return codes. The man page for ftp doesn't list return codes. Does anyone know where to find a list? Anyone with experience with this? We have other scripts that grep for certain return strings in the log, and they send an email when in error. However, they often miss unanticipated codes.
I am then putting the reason into the log and the email.










share|improve this question
















I am currently creating an overnight job that calls a Unix script which in turn creates and transfers a file using ftp. I would like to check all possible return codes. The man page for ftp doesn't list return codes. Does anyone know where to find a list? Anyone with experience with this? We have other scripts that grep for certain return strings in the log, and they send an email when in error. However, they often miss unanticipated codes.
I am then putting the reason into the log and the email.







unix ftp scripting return






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 6 '14 at 12:44









Cristian Ciupitu

14.9k54264




14.9k54264










asked Sep 26 '08 at 14:53









Glenn WarkGlenn Wark

80241121




80241121













  • Thanks guys, as you can probably tell, my unix scripting is not that far along. I'm basically working from other scripts by people that used to work here. However, I'd like to make it more bulletproof than what I've found so far. I appreciate all answers so far.

    – Glenn Wark
    Sep 26 '08 at 15:49











  • Basically my code so far is as follows: echo " open $ftpip pwd binary lcd /out cd /in mput $datafile quit"|ftp -iv > $ftpreturn The -v option looks like what I need. But the $ftpreturn variable is blank. The file isn't getting ftp'd and is failing silently. What am I missing?

    – Glenn Wark
    Sep 26 '08 at 15:51



















  • Thanks guys, as you can probably tell, my unix scripting is not that far along. I'm basically working from other scripts by people that used to work here. However, I'd like to make it more bulletproof than what I've found so far. I appreciate all answers so far.

    – Glenn Wark
    Sep 26 '08 at 15:49











  • Basically my code so far is as follows: echo " open $ftpip pwd binary lcd /out cd /in mput $datafile quit"|ftp -iv > $ftpreturn The -v option looks like what I need. But the $ftpreturn variable is blank. The file isn't getting ftp'd and is failing silently. What am I missing?

    – Glenn Wark
    Sep 26 '08 at 15:51

















Thanks guys, as you can probably tell, my unix scripting is not that far along. I'm basically working from other scripts by people that used to work here. However, I'd like to make it more bulletproof than what I've found so far. I appreciate all answers so far.

– Glenn Wark
Sep 26 '08 at 15:49





Thanks guys, as you can probably tell, my unix scripting is not that far along. I'm basically working from other scripts by people that used to work here. However, I'd like to make it more bulletproof than what I've found so far. I appreciate all answers so far.

– Glenn Wark
Sep 26 '08 at 15:49













Basically my code so far is as follows: echo " open $ftpip pwd binary lcd /out cd /in mput $datafile quit"|ftp -iv > $ftpreturn The -v option looks like what I need. But the $ftpreturn variable is blank. The file isn't getting ftp'd and is failing silently. What am I missing?

– Glenn Wark
Sep 26 '08 at 15:51





Basically my code so far is as follows: echo " open $ftpip pwd binary lcd /out cd /in mput $datafile quit"|ftp -iv > $ftpreturn The -v option looks like what I need. But the $ftpreturn variable is blank. The file isn't getting ftp'd and is failing silently. What am I missing?

– Glenn Wark
Sep 26 '08 at 15:51












9 Answers
9






active

oldest

votes


















7














The ftp command does not return anything other than zero on most implementations that I've come across.



It's much better to process the three digit codes in the log - and if you're sending a binary file, you can check that bytes sent was correct.



The three digit codes are called 'series codes' and a list can be found here






share|improve this answer


























  • Sorry to be a pain, but I have 2 questions. 1) But where is the log? I assumed that it would be in $ftpreturn. 2) How do I check the bytes sent?

    – Glenn Wark
    Sep 26 '08 at 16:35











  • I figured it out. Thanks for the help. Glenn.

    – Glenn Wark
    Oct 3 '08 at 18:50











  • Hint: use -v (verbose) to get the return codes from FTP Command.

    – Sandeep Jindal
    Aug 19 '15 at 13:57



















5














I wrote a script to transfer only one file at a time and in that script use grep to check for the 226 Transfer complete message. If it finds it, grep returns 0.



ftp -niv < "$2"_ftp.tmp | grep "^226 "





share|improve this answer

































    4














    Install the ncftp package. It comes with ncftpget and ncftpput which will each attempt to upload/download a single file, and return with a descriptive error code if there is a problem. See the “Diagnostics” section of the man page.






    share|improve this answer

































      3














      I think it is easier to run the ftp and check the exit code of ftp if something gone wrong.



      I did this like the example below:



      # ...
      ftp -i -n $HOST 2>&1 1> $FTPLOG << EOF
      quote USER $USER
      quote PASS $PASSWD
      cd $RFOLDER
      binary
      put $FOLDER/$FILE.sql.Z $FILE.sql.Z
      bye
      EOF

      # Check the ftp util exit code (0 is ok, every else means an error occurred!)
      EXITFTP=$?
      if test $EXITFTP -ne 0; then echo "$D ERROR FTP" >> $LOG; exit 3; fi
      if (grep "^Not connected." $FTPLOG); then echo "$D ERROR FTP CONNECT" >> $LOG; fi
      if (grep "No such file" $FTPLOG); then echo "$D ERROR FTP NO SUCH FILE" >> $LOG; fi
      if (grep "access denied" $FTPLOG ); then echo "$D ERROR FTP ACCESS DENIED" >> $LOG; fi
      if (grep "^Please login" $FTPLOG ); then echo "$D ERROR FTP LOGIN" >> $LOG; fi


      Edit: To catch errors I grep the output of the ftp command. But it's truly it's not the best solution.



      I don't know how familier you are with a Scriptlanguage like Perl, Python or Ruby. They all have a FTP module which you can be used. This enables you to check for errors after each command. Here is a example in Perl:



      #!/usr/bin/perl -w
      use Net::FTP;
      $ftp = Net::FTP->new("example.net") or die "Cannot connect to example.net: $@";
      $ftp->login("username", "password") or die "Cannot login ", $ftp->message;
      $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message;
      $ftp->binary;
      $ftp->put("foo.bar") or die "Failed to upload ", $ftp->message;
      $ftp->quit;


      For this logic to work user need to redirect STDERR as well from ftp command as below



      ftp -i -n $HOST >$FTPLOG 2>&1 << EOF


      Below command will always assign 0 (success) as because ftp command wont return success or failure. So user should not depend on it



      EXITFTP=$?





      share|improve this answer


























      • From what I understand, the ftp return can't be trusted. As mentioned by Colin below.

        – Glenn Wark
        Sep 26 '08 at 16:38



















      1














      lame answer I know, but how about getting the ftp sources and see for yourself






      share|improve this answer
























      • How do I go about this?

        – Glenn Wark
        Sep 26 '08 at 16:35



















      1














      I like the solution from Anurag, for the bytes transfered problem I have extended the command with grep -v "bytes"



      ie



      grep "^530" ftp_out2.txt | grep -v "byte"



      -instead of 530 you can use all the error codes as Anurag did.






      share|improve this answer































        0














        You said you wanted to FTP the file there, but you didn't say whether or not regular BSD FTP client was the only way you wanted to get it there. BSD FTP doesn't give you a return code for error conditions necessitating all that parsing, but there are a whole series of other Unix programs that can be used to transfer files by FTP if you or your administrator will install them. I will give you some examples of ways to transfer a file by FTP while still catching all error conditions with little amounts of code.



        FTPUSER is your ftp user login name



        FTPPASS is your ftp password



        FILE is the local file you want to upload without any path info (eg file1.txt, not /whatever/file1.txt or whatever/file1.txt



        FTPHOST is the remote machine you want to FTP to



        REMOTEDIR is an ABSOLUTE PATH to the location on the remote machine you want to upload to



        Here are the examples:



        curl --user $FTPUSER:$FTPPASS -T $FILE ftp://$FTPHOST/%2f$REMOTEDIR



        ftp-upload --host $FTPHOST --user $FTPUSER --password $FTPPASS --as $REMOTEDIR/$FILE $FILE



        tnftp -u ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE $FILE



        wput $FILE ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE



        All of these programs will return a nonzero exit code if anything at all goes wrong, along with text that indicates what failed. You can test for this and then do whatever you want with the output, log it, email it, etc as you wished.



        Please note the following however:




        1. "%2f" is used in URLs to indicate that the following path is an absolute path on the remote machine. However, if your FTP server chroots you, you won't be able to bypass this.


        2. for the commands above that use an actual URL (ftp://etc) to the server with the user and password embedded in it, the username and password MUST be URL-encoded if it contains special characters.


        3. In some cases you can be flexible with the remote directory being absolute and local file being just the plain filename once you are familiar with the syntax of each program. You might just have to add a local directory environment variable or just hardcode everything.


        4. IF you really, absolutely MUST use regular FTP client, one way you can test for failure is by, inside your script, including first a command that PUTs the file, followed by another that does a GET of the same file returning it under a different name. After FTP exits, simply test for the existence of the downloaded file in your shell script, or even checksum it against the original to make sure it transferred correctly. Yeah that stinks, but in my opinion it is better to have code that is easy to read than do tons of parsing for every possible error condition. BSD FTP is just not all that great.







        share|improve this answer































          0














          Here is what I finally went with. Thanks for all the help. All the answers help lead me in the right direction.
          It may be a little overkill, checking both the result and the log, but it should cover all of the bases.



          echo "open ftp_ip
          pwd
          binary
          lcd /out
          cd /in
          mput datafile.csv
          quit"|ftp -iv > ftpreturn.log

          ftpresult=$?

          bytesindatafile=`wc -c datafile.csv | cut -d " " -f 1`
          bytestransferred=`grep -e '^[0-9]* bytes sent' ftpreturn.log | cut -d " " -f 1`
          ftptransfercomplete=`grep -e '226 ' ftpreturn.log | cut -d " " -f 1`

          echo "-- FTP result code: $ftpresult" >> ftpreturn.log
          echo "-- bytes in datafile: $bytesindatafile bytes" >> ftpreturn.log
          echo "-- bytes transferred: $bytestransferred bytes sent" >> ftpreturn.log

          if [ "$ftpresult" != "0" ] || [ "$bytestransferred" != "$bytesindatafile" ] || ["$ftptransfercomplete" != "226" ]
          then
          echo "-- *abend* FTP Error occurred" >> ftpreturn.log
          mailx -s 'FTP error' `cat email.lst` < ftpreturn.log
          else
          echo "-- file sent via ftp successfully" >> ftpreturn.log
          fi





          share|improve this answer

































            -1














            Why not just store all output from the command to a log file, then check the return code from the command and, if it's not 0, send the log file in the email?






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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%2fstackoverflow.com%2fquestions%2f140012%2fchecking-ftp-return-codes-from-unix-script%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              9 Answers
              9






              active

              oldest

              votes








              9 Answers
              9






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              7














              The ftp command does not return anything other than zero on most implementations that I've come across.



              It's much better to process the three digit codes in the log - and if you're sending a binary file, you can check that bytes sent was correct.



              The three digit codes are called 'series codes' and a list can be found here






              share|improve this answer


























              • Sorry to be a pain, but I have 2 questions. 1) But where is the log? I assumed that it would be in $ftpreturn. 2) How do I check the bytes sent?

                – Glenn Wark
                Sep 26 '08 at 16:35











              • I figured it out. Thanks for the help. Glenn.

                – Glenn Wark
                Oct 3 '08 at 18:50











              • Hint: use -v (verbose) to get the return codes from FTP Command.

                – Sandeep Jindal
                Aug 19 '15 at 13:57
















              7














              The ftp command does not return anything other than zero on most implementations that I've come across.



              It's much better to process the three digit codes in the log - and if you're sending a binary file, you can check that bytes sent was correct.



              The three digit codes are called 'series codes' and a list can be found here






              share|improve this answer


























              • Sorry to be a pain, but I have 2 questions. 1) But where is the log? I assumed that it would be in $ftpreturn. 2) How do I check the bytes sent?

                – Glenn Wark
                Sep 26 '08 at 16:35











              • I figured it out. Thanks for the help. Glenn.

                – Glenn Wark
                Oct 3 '08 at 18:50











              • Hint: use -v (verbose) to get the return codes from FTP Command.

                – Sandeep Jindal
                Aug 19 '15 at 13:57














              7












              7








              7







              The ftp command does not return anything other than zero on most implementations that I've come across.



              It's much better to process the three digit codes in the log - and if you're sending a binary file, you can check that bytes sent was correct.



              The three digit codes are called 'series codes' and a list can be found here






              share|improve this answer















              The ftp command does not return anything other than zero on most implementations that I've come across.



              It's much better to process the three digit codes in the log - and if you're sending a binary file, you can check that bytes sent was correct.



              The three digit codes are called 'series codes' and a list can be found here







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 6 '14 at 12:45









              Cristian Ciupitu

              14.9k54264




              14.9k54264










              answered Sep 26 '08 at 15:03









              ColinYoungerColinYounger

              4,57542633




              4,57542633













              • Sorry to be a pain, but I have 2 questions. 1) But where is the log? I assumed that it would be in $ftpreturn. 2) How do I check the bytes sent?

                – Glenn Wark
                Sep 26 '08 at 16:35











              • I figured it out. Thanks for the help. Glenn.

                – Glenn Wark
                Oct 3 '08 at 18:50











              • Hint: use -v (verbose) to get the return codes from FTP Command.

                – Sandeep Jindal
                Aug 19 '15 at 13:57



















              • Sorry to be a pain, but I have 2 questions. 1) But where is the log? I assumed that it would be in $ftpreturn. 2) How do I check the bytes sent?

                – Glenn Wark
                Sep 26 '08 at 16:35











              • I figured it out. Thanks for the help. Glenn.

                – Glenn Wark
                Oct 3 '08 at 18:50











              • Hint: use -v (verbose) to get the return codes from FTP Command.

                – Sandeep Jindal
                Aug 19 '15 at 13:57

















              Sorry to be a pain, but I have 2 questions. 1) But where is the log? I assumed that it would be in $ftpreturn. 2) How do I check the bytes sent?

              – Glenn Wark
              Sep 26 '08 at 16:35





              Sorry to be a pain, but I have 2 questions. 1) But where is the log? I assumed that it would be in $ftpreturn. 2) How do I check the bytes sent?

              – Glenn Wark
              Sep 26 '08 at 16:35













              I figured it out. Thanks for the help. Glenn.

              – Glenn Wark
              Oct 3 '08 at 18:50





              I figured it out. Thanks for the help. Glenn.

              – Glenn Wark
              Oct 3 '08 at 18:50













              Hint: use -v (verbose) to get the return codes from FTP Command.

              – Sandeep Jindal
              Aug 19 '15 at 13:57





              Hint: use -v (verbose) to get the return codes from FTP Command.

              – Sandeep Jindal
              Aug 19 '15 at 13:57













              5














              I wrote a script to transfer only one file at a time and in that script use grep to check for the 226 Transfer complete message. If it finds it, grep returns 0.



              ftp -niv < "$2"_ftp.tmp | grep "^226 "





              share|improve this answer






























                5














                I wrote a script to transfer only one file at a time and in that script use grep to check for the 226 Transfer complete message. If it finds it, grep returns 0.



                ftp -niv < "$2"_ftp.tmp | grep "^226 "





                share|improve this answer




























                  5












                  5








                  5







                  I wrote a script to transfer only one file at a time and in that script use grep to check for the 226 Transfer complete message. If it finds it, grep returns 0.



                  ftp -niv < "$2"_ftp.tmp | grep "^226 "





                  share|improve this answer















                  I wrote a script to transfer only one file at a time and in that script use grep to check for the 226 Transfer complete message. If it finds it, grep returns 0.



                  ftp -niv < "$2"_ftp.tmp | grep "^226 "






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 16 '11 at 8:31









                  JMax

                  20.6k85785




                  20.6k85785










                  answered Dec 14 '10 at 18:27









                  David LapchukDavid Lapchuk

                  5111




                  5111























                      4














                      Install the ncftp package. It comes with ncftpget and ncftpput which will each attempt to upload/download a single file, and return with a descriptive error code if there is a problem. See the “Diagnostics” section of the man page.






                      share|improve this answer






























                        4














                        Install the ncftp package. It comes with ncftpget and ncftpput which will each attempt to upload/download a single file, and return with a descriptive error code if there is a problem. See the “Diagnostics” section of the man page.






                        share|improve this answer




























                          4












                          4








                          4







                          Install the ncftp package. It comes with ncftpget and ncftpput which will each attempt to upload/download a single file, and return with a descriptive error code if there is a problem. See the “Diagnostics” section of the man page.






                          share|improve this answer















                          Install the ncftp package. It comes with ncftpget and ncftpput which will each attempt to upload/download a single file, and return with a descriptive error code if there is a problem. See the “Diagnostics” section of the man page.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 6 '14 at 18:49

























                          answered Sep 28 '08 at 1:30









                          andrewdotnandrewdotn

                          23.3k26699




                          23.3k26699























                              3














                              I think it is easier to run the ftp and check the exit code of ftp if something gone wrong.



                              I did this like the example below:



                              # ...
                              ftp -i -n $HOST 2>&1 1> $FTPLOG << EOF
                              quote USER $USER
                              quote PASS $PASSWD
                              cd $RFOLDER
                              binary
                              put $FOLDER/$FILE.sql.Z $FILE.sql.Z
                              bye
                              EOF

                              # Check the ftp util exit code (0 is ok, every else means an error occurred!)
                              EXITFTP=$?
                              if test $EXITFTP -ne 0; then echo "$D ERROR FTP" >> $LOG; exit 3; fi
                              if (grep "^Not connected." $FTPLOG); then echo "$D ERROR FTP CONNECT" >> $LOG; fi
                              if (grep "No such file" $FTPLOG); then echo "$D ERROR FTP NO SUCH FILE" >> $LOG; fi
                              if (grep "access denied" $FTPLOG ); then echo "$D ERROR FTP ACCESS DENIED" >> $LOG; fi
                              if (grep "^Please login" $FTPLOG ); then echo "$D ERROR FTP LOGIN" >> $LOG; fi


                              Edit: To catch errors I grep the output of the ftp command. But it's truly it's not the best solution.



                              I don't know how familier you are with a Scriptlanguage like Perl, Python or Ruby. They all have a FTP module which you can be used. This enables you to check for errors after each command. Here is a example in Perl:



                              #!/usr/bin/perl -w
                              use Net::FTP;
                              $ftp = Net::FTP->new("example.net") or die "Cannot connect to example.net: $@";
                              $ftp->login("username", "password") or die "Cannot login ", $ftp->message;
                              $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message;
                              $ftp->binary;
                              $ftp->put("foo.bar") or die "Failed to upload ", $ftp->message;
                              $ftp->quit;


                              For this logic to work user need to redirect STDERR as well from ftp command as below



                              ftp -i -n $HOST >$FTPLOG 2>&1 << EOF


                              Below command will always assign 0 (success) as because ftp command wont return success or failure. So user should not depend on it



                              EXITFTP=$?





                              share|improve this answer


























                              • From what I understand, the ftp return can't be trusted. As mentioned by Colin below.

                                – Glenn Wark
                                Sep 26 '08 at 16:38
















                              3














                              I think it is easier to run the ftp and check the exit code of ftp if something gone wrong.



                              I did this like the example below:



                              # ...
                              ftp -i -n $HOST 2>&1 1> $FTPLOG << EOF
                              quote USER $USER
                              quote PASS $PASSWD
                              cd $RFOLDER
                              binary
                              put $FOLDER/$FILE.sql.Z $FILE.sql.Z
                              bye
                              EOF

                              # Check the ftp util exit code (0 is ok, every else means an error occurred!)
                              EXITFTP=$?
                              if test $EXITFTP -ne 0; then echo "$D ERROR FTP" >> $LOG; exit 3; fi
                              if (grep "^Not connected." $FTPLOG); then echo "$D ERROR FTP CONNECT" >> $LOG; fi
                              if (grep "No such file" $FTPLOG); then echo "$D ERROR FTP NO SUCH FILE" >> $LOG; fi
                              if (grep "access denied" $FTPLOG ); then echo "$D ERROR FTP ACCESS DENIED" >> $LOG; fi
                              if (grep "^Please login" $FTPLOG ); then echo "$D ERROR FTP LOGIN" >> $LOG; fi


                              Edit: To catch errors I grep the output of the ftp command. But it's truly it's not the best solution.



                              I don't know how familier you are with a Scriptlanguage like Perl, Python or Ruby. They all have a FTP module which you can be used. This enables you to check for errors after each command. Here is a example in Perl:



                              #!/usr/bin/perl -w
                              use Net::FTP;
                              $ftp = Net::FTP->new("example.net") or die "Cannot connect to example.net: $@";
                              $ftp->login("username", "password") or die "Cannot login ", $ftp->message;
                              $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message;
                              $ftp->binary;
                              $ftp->put("foo.bar") or die "Failed to upload ", $ftp->message;
                              $ftp->quit;


                              For this logic to work user need to redirect STDERR as well from ftp command as below



                              ftp -i -n $HOST >$FTPLOG 2>&1 << EOF


                              Below command will always assign 0 (success) as because ftp command wont return success or failure. So user should not depend on it



                              EXITFTP=$?





                              share|improve this answer


























                              • From what I understand, the ftp return can't be trusted. As mentioned by Colin below.

                                – Glenn Wark
                                Sep 26 '08 at 16:38














                              3












                              3








                              3







                              I think it is easier to run the ftp and check the exit code of ftp if something gone wrong.



                              I did this like the example below:



                              # ...
                              ftp -i -n $HOST 2>&1 1> $FTPLOG << EOF
                              quote USER $USER
                              quote PASS $PASSWD
                              cd $RFOLDER
                              binary
                              put $FOLDER/$FILE.sql.Z $FILE.sql.Z
                              bye
                              EOF

                              # Check the ftp util exit code (0 is ok, every else means an error occurred!)
                              EXITFTP=$?
                              if test $EXITFTP -ne 0; then echo "$D ERROR FTP" >> $LOG; exit 3; fi
                              if (grep "^Not connected." $FTPLOG); then echo "$D ERROR FTP CONNECT" >> $LOG; fi
                              if (grep "No such file" $FTPLOG); then echo "$D ERROR FTP NO SUCH FILE" >> $LOG; fi
                              if (grep "access denied" $FTPLOG ); then echo "$D ERROR FTP ACCESS DENIED" >> $LOG; fi
                              if (grep "^Please login" $FTPLOG ); then echo "$D ERROR FTP LOGIN" >> $LOG; fi


                              Edit: To catch errors I grep the output of the ftp command. But it's truly it's not the best solution.



                              I don't know how familier you are with a Scriptlanguage like Perl, Python or Ruby. They all have a FTP module which you can be used. This enables you to check for errors after each command. Here is a example in Perl:



                              #!/usr/bin/perl -w
                              use Net::FTP;
                              $ftp = Net::FTP->new("example.net") or die "Cannot connect to example.net: $@";
                              $ftp->login("username", "password") or die "Cannot login ", $ftp->message;
                              $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message;
                              $ftp->binary;
                              $ftp->put("foo.bar") or die "Failed to upload ", $ftp->message;
                              $ftp->quit;


                              For this logic to work user need to redirect STDERR as well from ftp command as below



                              ftp -i -n $HOST >$FTPLOG 2>&1 << EOF


                              Below command will always assign 0 (success) as because ftp command wont return success or failure. So user should not depend on it



                              EXITFTP=$?





                              share|improve this answer















                              I think it is easier to run the ftp and check the exit code of ftp if something gone wrong.



                              I did this like the example below:



                              # ...
                              ftp -i -n $HOST 2>&1 1> $FTPLOG << EOF
                              quote USER $USER
                              quote PASS $PASSWD
                              cd $RFOLDER
                              binary
                              put $FOLDER/$FILE.sql.Z $FILE.sql.Z
                              bye
                              EOF

                              # Check the ftp util exit code (0 is ok, every else means an error occurred!)
                              EXITFTP=$?
                              if test $EXITFTP -ne 0; then echo "$D ERROR FTP" >> $LOG; exit 3; fi
                              if (grep "^Not connected." $FTPLOG); then echo "$D ERROR FTP CONNECT" >> $LOG; fi
                              if (grep "No such file" $FTPLOG); then echo "$D ERROR FTP NO SUCH FILE" >> $LOG; fi
                              if (grep "access denied" $FTPLOG ); then echo "$D ERROR FTP ACCESS DENIED" >> $LOG; fi
                              if (grep "^Please login" $FTPLOG ); then echo "$D ERROR FTP LOGIN" >> $LOG; fi


                              Edit: To catch errors I grep the output of the ftp command. But it's truly it's not the best solution.



                              I don't know how familier you are with a Scriptlanguage like Perl, Python or Ruby. They all have a FTP module which you can be used. This enables you to check for errors after each command. Here is a example in Perl:



                              #!/usr/bin/perl -w
                              use Net::FTP;
                              $ftp = Net::FTP->new("example.net") or die "Cannot connect to example.net: $@";
                              $ftp->login("username", "password") or die "Cannot login ", $ftp->message;
                              $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message;
                              $ftp->binary;
                              $ftp->put("foo.bar") or die "Failed to upload ", $ftp->message;
                              $ftp->quit;


                              For this logic to work user need to redirect STDERR as well from ftp command as below



                              ftp -i -n $HOST >$FTPLOG 2>&1 << EOF


                              Below command will always assign 0 (success) as because ftp command wont return success or failure. So user should not depend on it



                              EXITFTP=$?






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 23 '18 at 4:52









                              Skynet

                              4,40452842




                              4,40452842










                              answered Sep 26 '08 at 15:57









                              jk.jk.

                              5,94322221




                              5,94322221













                              • From what I understand, the ftp return can't be trusted. As mentioned by Colin below.

                                – Glenn Wark
                                Sep 26 '08 at 16:38



















                              • From what I understand, the ftp return can't be trusted. As mentioned by Colin below.

                                – Glenn Wark
                                Sep 26 '08 at 16:38

















                              From what I understand, the ftp return can't be trusted. As mentioned by Colin below.

                              – Glenn Wark
                              Sep 26 '08 at 16:38





                              From what I understand, the ftp return can't be trusted. As mentioned by Colin below.

                              – Glenn Wark
                              Sep 26 '08 at 16:38











                              1














                              lame answer I know, but how about getting the ftp sources and see for yourself






                              share|improve this answer
























                              • How do I go about this?

                                – Glenn Wark
                                Sep 26 '08 at 16:35
















                              1














                              lame answer I know, but how about getting the ftp sources and see for yourself






                              share|improve this answer
























                              • How do I go about this?

                                – Glenn Wark
                                Sep 26 '08 at 16:35














                              1












                              1








                              1







                              lame answer I know, but how about getting the ftp sources and see for yourself






                              share|improve this answer













                              lame answer I know, but how about getting the ftp sources and see for yourself







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Sep 26 '08 at 15:03







                              lr2




















                              • How do I go about this?

                                – Glenn Wark
                                Sep 26 '08 at 16:35



















                              • How do I go about this?

                                – Glenn Wark
                                Sep 26 '08 at 16:35

















                              How do I go about this?

                              – Glenn Wark
                              Sep 26 '08 at 16:35





                              How do I go about this?

                              – Glenn Wark
                              Sep 26 '08 at 16:35











                              1














                              I like the solution from Anurag, for the bytes transfered problem I have extended the command with grep -v "bytes"



                              ie



                              grep "^530" ftp_out2.txt | grep -v "byte"



                              -instead of 530 you can use all the error codes as Anurag did.






                              share|improve this answer




























                                1














                                I like the solution from Anurag, for the bytes transfered problem I have extended the command with grep -v "bytes"



                                ie



                                grep "^530" ftp_out2.txt | grep -v "byte"



                                -instead of 530 you can use all the error codes as Anurag did.






                                share|improve this answer


























                                  1












                                  1








                                  1







                                  I like the solution from Anurag, for the bytes transfered problem I have extended the command with grep -v "bytes"



                                  ie



                                  grep "^530" ftp_out2.txt | grep -v "byte"



                                  -instead of 530 you can use all the error codes as Anurag did.






                                  share|improve this answer













                                  I like the solution from Anurag, for the bytes transfered problem I have extended the command with grep -v "bytes"



                                  ie



                                  grep "^530" ftp_out2.txt | grep -v "byte"



                                  -instead of 530 you can use all the error codes as Anurag did.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Sep 23 '10 at 10:34









                                  eNormeNorm

                                  111




                                  111























                                      0














                                      You said you wanted to FTP the file there, but you didn't say whether or not regular BSD FTP client was the only way you wanted to get it there. BSD FTP doesn't give you a return code for error conditions necessitating all that parsing, but there are a whole series of other Unix programs that can be used to transfer files by FTP if you or your administrator will install them. I will give you some examples of ways to transfer a file by FTP while still catching all error conditions with little amounts of code.



                                      FTPUSER is your ftp user login name



                                      FTPPASS is your ftp password



                                      FILE is the local file you want to upload without any path info (eg file1.txt, not /whatever/file1.txt or whatever/file1.txt



                                      FTPHOST is the remote machine you want to FTP to



                                      REMOTEDIR is an ABSOLUTE PATH to the location on the remote machine you want to upload to



                                      Here are the examples:



                                      curl --user $FTPUSER:$FTPPASS -T $FILE ftp://$FTPHOST/%2f$REMOTEDIR



                                      ftp-upload --host $FTPHOST --user $FTPUSER --password $FTPPASS --as $REMOTEDIR/$FILE $FILE



                                      tnftp -u ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE $FILE



                                      wput $FILE ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE



                                      All of these programs will return a nonzero exit code if anything at all goes wrong, along with text that indicates what failed. You can test for this and then do whatever you want with the output, log it, email it, etc as you wished.



                                      Please note the following however:




                                      1. "%2f" is used in URLs to indicate that the following path is an absolute path on the remote machine. However, if your FTP server chroots you, you won't be able to bypass this.


                                      2. for the commands above that use an actual URL (ftp://etc) to the server with the user and password embedded in it, the username and password MUST be URL-encoded if it contains special characters.


                                      3. In some cases you can be flexible with the remote directory being absolute and local file being just the plain filename once you are familiar with the syntax of each program. You might just have to add a local directory environment variable or just hardcode everything.


                                      4. IF you really, absolutely MUST use regular FTP client, one way you can test for failure is by, inside your script, including first a command that PUTs the file, followed by another that does a GET of the same file returning it under a different name. After FTP exits, simply test for the existence of the downloaded file in your shell script, or even checksum it against the original to make sure it transferred correctly. Yeah that stinks, but in my opinion it is better to have code that is easy to read than do tons of parsing for every possible error condition. BSD FTP is just not all that great.







                                      share|improve this answer




























                                        0














                                        You said you wanted to FTP the file there, but you didn't say whether or not regular BSD FTP client was the only way you wanted to get it there. BSD FTP doesn't give you a return code for error conditions necessitating all that parsing, but there are a whole series of other Unix programs that can be used to transfer files by FTP if you or your administrator will install them. I will give you some examples of ways to transfer a file by FTP while still catching all error conditions with little amounts of code.



                                        FTPUSER is your ftp user login name



                                        FTPPASS is your ftp password



                                        FILE is the local file you want to upload without any path info (eg file1.txt, not /whatever/file1.txt or whatever/file1.txt



                                        FTPHOST is the remote machine you want to FTP to



                                        REMOTEDIR is an ABSOLUTE PATH to the location on the remote machine you want to upload to



                                        Here are the examples:



                                        curl --user $FTPUSER:$FTPPASS -T $FILE ftp://$FTPHOST/%2f$REMOTEDIR



                                        ftp-upload --host $FTPHOST --user $FTPUSER --password $FTPPASS --as $REMOTEDIR/$FILE $FILE



                                        tnftp -u ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE $FILE



                                        wput $FILE ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE



                                        All of these programs will return a nonzero exit code if anything at all goes wrong, along with text that indicates what failed. You can test for this and then do whatever you want with the output, log it, email it, etc as you wished.



                                        Please note the following however:




                                        1. "%2f" is used in URLs to indicate that the following path is an absolute path on the remote machine. However, if your FTP server chroots you, you won't be able to bypass this.


                                        2. for the commands above that use an actual URL (ftp://etc) to the server with the user and password embedded in it, the username and password MUST be URL-encoded if it contains special characters.


                                        3. In some cases you can be flexible with the remote directory being absolute and local file being just the plain filename once you are familiar with the syntax of each program. You might just have to add a local directory environment variable or just hardcode everything.


                                        4. IF you really, absolutely MUST use regular FTP client, one way you can test for failure is by, inside your script, including first a command that PUTs the file, followed by another that does a GET of the same file returning it under a different name. After FTP exits, simply test for the existence of the downloaded file in your shell script, or even checksum it against the original to make sure it transferred correctly. Yeah that stinks, but in my opinion it is better to have code that is easy to read than do tons of parsing for every possible error condition. BSD FTP is just not all that great.







                                        share|improve this answer


























                                          0












                                          0








                                          0







                                          You said you wanted to FTP the file there, but you didn't say whether or not regular BSD FTP client was the only way you wanted to get it there. BSD FTP doesn't give you a return code for error conditions necessitating all that parsing, but there are a whole series of other Unix programs that can be used to transfer files by FTP if you or your administrator will install them. I will give you some examples of ways to transfer a file by FTP while still catching all error conditions with little amounts of code.



                                          FTPUSER is your ftp user login name



                                          FTPPASS is your ftp password



                                          FILE is the local file you want to upload without any path info (eg file1.txt, not /whatever/file1.txt or whatever/file1.txt



                                          FTPHOST is the remote machine you want to FTP to



                                          REMOTEDIR is an ABSOLUTE PATH to the location on the remote machine you want to upload to



                                          Here are the examples:



                                          curl --user $FTPUSER:$FTPPASS -T $FILE ftp://$FTPHOST/%2f$REMOTEDIR



                                          ftp-upload --host $FTPHOST --user $FTPUSER --password $FTPPASS --as $REMOTEDIR/$FILE $FILE



                                          tnftp -u ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE $FILE



                                          wput $FILE ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE



                                          All of these programs will return a nonzero exit code if anything at all goes wrong, along with text that indicates what failed. You can test for this and then do whatever you want with the output, log it, email it, etc as you wished.



                                          Please note the following however:




                                          1. "%2f" is used in URLs to indicate that the following path is an absolute path on the remote machine. However, if your FTP server chroots you, you won't be able to bypass this.


                                          2. for the commands above that use an actual URL (ftp://etc) to the server with the user and password embedded in it, the username and password MUST be URL-encoded if it contains special characters.


                                          3. In some cases you can be flexible with the remote directory being absolute and local file being just the plain filename once you are familiar with the syntax of each program. You might just have to add a local directory environment variable or just hardcode everything.


                                          4. IF you really, absolutely MUST use regular FTP client, one way you can test for failure is by, inside your script, including first a command that PUTs the file, followed by another that does a GET of the same file returning it under a different name. After FTP exits, simply test for the existence of the downloaded file in your shell script, or even checksum it against the original to make sure it transferred correctly. Yeah that stinks, but in my opinion it is better to have code that is easy to read than do tons of parsing for every possible error condition. BSD FTP is just not all that great.







                                          share|improve this answer













                                          You said you wanted to FTP the file there, but you didn't say whether or not regular BSD FTP client was the only way you wanted to get it there. BSD FTP doesn't give you a return code for error conditions necessitating all that parsing, but there are a whole series of other Unix programs that can be used to transfer files by FTP if you or your administrator will install them. I will give you some examples of ways to transfer a file by FTP while still catching all error conditions with little amounts of code.



                                          FTPUSER is your ftp user login name



                                          FTPPASS is your ftp password



                                          FILE is the local file you want to upload without any path info (eg file1.txt, not /whatever/file1.txt or whatever/file1.txt



                                          FTPHOST is the remote machine you want to FTP to



                                          REMOTEDIR is an ABSOLUTE PATH to the location on the remote machine you want to upload to



                                          Here are the examples:



                                          curl --user $FTPUSER:$FTPPASS -T $FILE ftp://$FTPHOST/%2f$REMOTEDIR



                                          ftp-upload --host $FTPHOST --user $FTPUSER --password $FTPPASS --as $REMOTEDIR/$FILE $FILE



                                          tnftp -u ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE $FILE



                                          wput $FILE ftp://$FTPUSER:$FTPPASS@$FTPHOST/%2f$REMOTEDIR/$FILE



                                          All of these programs will return a nonzero exit code if anything at all goes wrong, along with text that indicates what failed. You can test for this and then do whatever you want with the output, log it, email it, etc as you wished.



                                          Please note the following however:




                                          1. "%2f" is used in URLs to indicate that the following path is an absolute path on the remote machine. However, if your FTP server chroots you, you won't be able to bypass this.


                                          2. for the commands above that use an actual URL (ftp://etc) to the server with the user and password embedded in it, the username and password MUST be URL-encoded if it contains special characters.


                                          3. In some cases you can be flexible with the remote directory being absolute and local file being just the plain filename once you are familiar with the syntax of each program. You might just have to add a local directory environment variable or just hardcode everything.


                                          4. IF you really, absolutely MUST use regular FTP client, one way you can test for failure is by, inside your script, including first a command that PUTs the file, followed by another that does a GET of the same file returning it under a different name. After FTP exits, simply test for the existence of the downloaded file in your shell script, or even checksum it against the original to make sure it transferred correctly. Yeah that stinks, but in my opinion it is better to have code that is easy to read than do tons of parsing for every possible error condition. BSD FTP is just not all that great.








                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Jan 30 '09 at 23:06









                                          DevelopersDevelopersDevelopersDevelopersDevelopersDevelopers

                                          22326




                                          22326























                                              0














                                              Here is what I finally went with. Thanks for all the help. All the answers help lead me in the right direction.
                                              It may be a little overkill, checking both the result and the log, but it should cover all of the bases.



                                              echo "open ftp_ip
                                              pwd
                                              binary
                                              lcd /out
                                              cd /in
                                              mput datafile.csv
                                              quit"|ftp -iv > ftpreturn.log

                                              ftpresult=$?

                                              bytesindatafile=`wc -c datafile.csv | cut -d " " -f 1`
                                              bytestransferred=`grep -e '^[0-9]* bytes sent' ftpreturn.log | cut -d " " -f 1`
                                              ftptransfercomplete=`grep -e '226 ' ftpreturn.log | cut -d " " -f 1`

                                              echo "-- FTP result code: $ftpresult" >> ftpreturn.log
                                              echo "-- bytes in datafile: $bytesindatafile bytes" >> ftpreturn.log
                                              echo "-- bytes transferred: $bytestransferred bytes sent" >> ftpreturn.log

                                              if [ "$ftpresult" != "0" ] || [ "$bytestransferred" != "$bytesindatafile" ] || ["$ftptransfercomplete" != "226" ]
                                              then
                                              echo "-- *abend* FTP Error occurred" >> ftpreturn.log
                                              mailx -s 'FTP error' `cat email.lst` < ftpreturn.log
                                              else
                                              echo "-- file sent via ftp successfully" >> ftpreturn.log
                                              fi





                                              share|improve this answer






























                                                0














                                                Here is what I finally went with. Thanks for all the help. All the answers help lead me in the right direction.
                                                It may be a little overkill, checking both the result and the log, but it should cover all of the bases.



                                                echo "open ftp_ip
                                                pwd
                                                binary
                                                lcd /out
                                                cd /in
                                                mput datafile.csv
                                                quit"|ftp -iv > ftpreturn.log

                                                ftpresult=$?

                                                bytesindatafile=`wc -c datafile.csv | cut -d " " -f 1`
                                                bytestransferred=`grep -e '^[0-9]* bytes sent' ftpreturn.log | cut -d " " -f 1`
                                                ftptransfercomplete=`grep -e '226 ' ftpreturn.log | cut -d " " -f 1`

                                                echo "-- FTP result code: $ftpresult" >> ftpreturn.log
                                                echo "-- bytes in datafile: $bytesindatafile bytes" >> ftpreturn.log
                                                echo "-- bytes transferred: $bytestransferred bytes sent" >> ftpreturn.log

                                                if [ "$ftpresult" != "0" ] || [ "$bytestransferred" != "$bytesindatafile" ] || ["$ftptransfercomplete" != "226" ]
                                                then
                                                echo "-- *abend* FTP Error occurred" >> ftpreturn.log
                                                mailx -s 'FTP error' `cat email.lst` < ftpreturn.log
                                                else
                                                echo "-- file sent via ftp successfully" >> ftpreturn.log
                                                fi





                                                share|improve this answer




























                                                  0












                                                  0








                                                  0







                                                  Here is what I finally went with. Thanks for all the help. All the answers help lead me in the right direction.
                                                  It may be a little overkill, checking both the result and the log, but it should cover all of the bases.



                                                  echo "open ftp_ip
                                                  pwd
                                                  binary
                                                  lcd /out
                                                  cd /in
                                                  mput datafile.csv
                                                  quit"|ftp -iv > ftpreturn.log

                                                  ftpresult=$?

                                                  bytesindatafile=`wc -c datafile.csv | cut -d " " -f 1`
                                                  bytestransferred=`grep -e '^[0-9]* bytes sent' ftpreturn.log | cut -d " " -f 1`
                                                  ftptransfercomplete=`grep -e '226 ' ftpreturn.log | cut -d " " -f 1`

                                                  echo "-- FTP result code: $ftpresult" >> ftpreturn.log
                                                  echo "-- bytes in datafile: $bytesindatafile bytes" >> ftpreturn.log
                                                  echo "-- bytes transferred: $bytestransferred bytes sent" >> ftpreturn.log

                                                  if [ "$ftpresult" != "0" ] || [ "$bytestransferred" != "$bytesindatafile" ] || ["$ftptransfercomplete" != "226" ]
                                                  then
                                                  echo "-- *abend* FTP Error occurred" >> ftpreturn.log
                                                  mailx -s 'FTP error' `cat email.lst` < ftpreturn.log
                                                  else
                                                  echo "-- file sent via ftp successfully" >> ftpreturn.log
                                                  fi





                                                  share|improve this answer















                                                  Here is what I finally went with. Thanks for all the help. All the answers help lead me in the right direction.
                                                  It may be a little overkill, checking both the result and the log, but it should cover all of the bases.



                                                  echo "open ftp_ip
                                                  pwd
                                                  binary
                                                  lcd /out
                                                  cd /in
                                                  mput datafile.csv
                                                  quit"|ftp -iv > ftpreturn.log

                                                  ftpresult=$?

                                                  bytesindatafile=`wc -c datafile.csv | cut -d " " -f 1`
                                                  bytestransferred=`grep -e '^[0-9]* bytes sent' ftpreturn.log | cut -d " " -f 1`
                                                  ftptransfercomplete=`grep -e '226 ' ftpreturn.log | cut -d " " -f 1`

                                                  echo "-- FTP result code: $ftpresult" >> ftpreturn.log
                                                  echo "-- bytes in datafile: $bytesindatafile bytes" >> ftpreturn.log
                                                  echo "-- bytes transferred: $bytestransferred bytes sent" >> ftpreturn.log

                                                  if [ "$ftpresult" != "0" ] || [ "$bytestransferred" != "$bytesindatafile" ] || ["$ftptransfercomplete" != "226" ]
                                                  then
                                                  echo "-- *abend* FTP Error occurred" >> ftpreturn.log
                                                  mailx -s 'FTP error' `cat email.lst` < ftpreturn.log
                                                  else
                                                  echo "-- file sent via ftp successfully" >> ftpreturn.log
                                                  fi






                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Nov 6 '14 at 12:42









                                                  Cristian Ciupitu

                                                  14.9k54264




                                                  14.9k54264










                                                  answered Oct 3 '08 at 19:18









                                                  Glenn WarkGlenn Wark

                                                  80241121




                                                  80241121























                                                      -1














                                                      Why not just store all output from the command to a log file, then check the return code from the command and, if it's not 0, send the log file in the email?






                                                      share|improve this answer




























                                                        -1














                                                        Why not just store all output from the command to a log file, then check the return code from the command and, if it's not 0, send the log file in the email?






                                                        share|improve this answer


























                                                          -1












                                                          -1








                                                          -1







                                                          Why not just store all output from the command to a log file, then check the return code from the command and, if it's not 0, send the log file in the email?






                                                          share|improve this answer













                                                          Why not just store all output from the command to a log file, then check the return code from the command and, if it's not 0, send the log file in the email?







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Sep 26 '08 at 15:03









                                                          Terence SimpsonTerence Simpson

                                                          2,85011617




                                                          2,85011617






























                                                              draft saved

                                                              draft discarded




















































                                                              Thanks for contributing an answer to Stack Overflow!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f140012%2fchecking-ftp-return-codes-from-unix-script%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







                                                              這個網誌中的熱門文章

                                                              Hercules Kyvelos

                                                              Tangent Lines Diagram Along Smooth Curve

                                                              Yusuf al-Mu'taman ibn Hud