Since it is tricky working with verbatim content, which is the case when dealing with listings, there is no easy single-command way out in my opinion. A two-step process using the filecontents package, however, is easy. Not as clean as diabonas' answer though...

\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
\usepackage{embedfile}% http://ctan.org/pkg/embedfile
\usepackage{filecontents}% http://ctan.org/pkg/filecontents
% Automatically embed listings file as attachment with \lstinputlisting
\let\lstinputlistingO=\lstinputlisting
\renewcommand{\lstinputlisting}[2][]{\embedfile{\detokenize{#2}}\lstinputlistingO[#1]{#2}}
\begin{document}
\lstinputlisting{A.tex} % Insert listing and embed in PDF
% Write listing to file
\begin{filecontents*}{B.tex}
Here is some more code
\end{filecontents*}
\lstinputlisting{B.tex} % Insert listing and embed in PDF
\end{document}
filecontents allows for using the filecontents (and filecontents*) environment outside the preamble of your document. If you don't like using filecontents* and would rather use something like \begin{listing}...\end{listing}, you could add the following to your document preamble:
\expandafter\let\expandafter\listing\csname filecontents*\endcsname
\expandafter\let\expandafter\endlisting\csname endfilecontents*\endcsname
However, adapting filecontents in general to accept an optional argument (which would include your listing formatting) is rather difficult, apart from rewriting the package (as far as I know).
This option saves the file first and then inputs it. The opposite approach of setting it first and then embedding it would be more difficult.