<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Script to extract files information from ftp server</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/script-to-extract-files-information-from-ftp-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/script-to-extract-files-information-from-ftp-server/</link>
	<description></description>
	<lastBuildDate>Wed, 19 Jun 2013 19:19:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: mailtobash</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/script-to-extract-files-information-from-ftp-server/#comment-61017</link>
		<dc:creator>mailtobash</dc:creator>
		<pubDate>Thu, 19 Mar 2009 08:51:58 +0000</pubDate>
		<guid isPermaLink="false">#comment-61017</guid>
		<description><![CDATA[Hi HolmanSAP
What is awkname.dat and awksize.dat ?
Can you please help me with this? 
The FLIST is not being created correctly in my script.

Please help.]]></description>
		<content:encoded><![CDATA[<p>Hi HolmanSAP<br />
What is awkname.dat and awksize.dat ?<br />
Can you please help me with this?<br />
The FLIST is not being created correctly in my script.</p>
<p>Please help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: holmansap</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/script-to-extract-files-information-from-ftp-server/#comment-56635</link>
		<dc:creator>holmansap</dc:creator>
		<pubDate>Wed, 24 Sep 2008 15:07:42 +0000</pubDate>
		<guid isPermaLink="false">#comment-56635</guid>
		<description><![CDATA[One method we use is to have the script execute FTP twice.  The first time it makes a connection to the ftp server, it issues the &quot;dir&quot; command and puts the output in a file on your local server. The script then closes the ftp session and checks the contents of the local file for anything that it should be picked up from the remote server.  The script then calls ftp a second time to do the actual transfer.  For each file transferred, you can then check the size of the local file to the information about the file that was obtained on the first ftp call.  If they are not the same, then the file was not transferred successfully.
For example:
#set a variable with the wildcard of files you are looking for 
FILEWC=&quot;S*&quot;
These two variables hold the value for the file name where I hold information from the ftp sessions
RFINFO=&quot;$LDIR/remote_directory_info.dif&quot;
RFINFO2=&quot;$LDIR/remote_directory_info2.dif&quot;
FTPLOG=&quot;$LDIR/ftplog.log&quot;
FTPHISTORY=&quot;$LDIR/ftp_history.log&quot;
# other variables are also used to store the name/address of the ftp server and the connection #information.  This makes it easy to modify the script to handle multiple ftp requirements:

ftp -nciv &gt; $FTPLOG 2&gt;&amp;1  &lt;&lt;EOT
  open $FTPSERVER
  user $RUSER $RPWD
  cd $RDIR
  dir $FILEWC $RFINFO
EOT
FTPSTATUS=$?
if [ $FTPSTATUS -ne 0 ] ; then
    return $FTPSTATUS
fi
NumToTransfer=`cat $RFINFO &#124; /usr/bin/wc -l `
if [ $NumToTransfer -eq 0 ]; then
   echo &quot;$CURDATE - No files to transfer&quot; &gt;&gt;$FTPHISTORY
else
   echo &quot;$CURDATE - Files to transfer: $NumToTransfer&quot; &gt;&gt;$FTPHISTORY
   FLIST=`cat $RFINFO &#124; awk -f $LDIR/awkname.dat`
fi

#in this code snippet, it builds a list of files to retrieve into a variable named FLIST

There is then another piece of our script that actually makes the second connection, for each file to be transferred, and retrieves the files. The variabel ftpmode is used to pass the command to set the transfer mode of either BIN or ASC.

for eachfile in $FLIST;
do
   ftp -nicv &gt;$FTPLOG 2&gt;&amp;1 &lt;&lt;EOT
     open $FTPSERVER
     user $RUSER $RPWD
     cd $RDIR
     $FTPMode
     dir $eachfile $RFINFO2
     get $eachfile
      quit
EOT
   FTPSTATUS=$?
   if [ $FTPSTATUS -ne 0 ] ; then
      return $FTPSTATUS
   fi
# Check the file size that was actually transfered
   FSIZE=`/usr/bin/ls -l $eachfile &#124; /usr/bin/awk &#039;{print $5}&#039;`
   RFSIZE=`cat $RFINFO &#124;grep $eachfile   &#124; awk  -f $LDIR/awksize.dat`
   RFSIZE2=`cat $RFINFO2 &#124;grep $eachfile &#124; awk  -f $LDIR/awksize.dat`
   if [ $FSIZE -ne $RFSIZE2 ] ; then
     echo &quot;$CURDATE - FILE $eachfile SIZE NOT EQUAL - $FSIZE - $RFSIZE2&quot; &gt;&gt;$FTPHISTORY
     echo &quot;File size not equal!!  Local: $FSIZE,  Remote: $RFSIZE2&quot; &gt;&gt; $FTPLOG
     FTPINCOMPLETE=1
     return
   fi
   echo &quot;$CURDATE - File $eachfile received - Size: $FSIZE&quot; &gt;&gt;$FTPHISTORY
   let NumTransferred=$NumTransferred+1
   if [ $NumTransferred -ge $FTPLIMIT ] &amp;&amp; [ $FTPLIMIT -ne 0 ] ; then
      break
   fi


I may have missed documenting some of the variables here, but I hope this helps.  
Regards,

Larry]]></description>
		<content:encoded><![CDATA[<p>One method we use is to have the script execute FTP twice.  The first time it makes a connection to the ftp server, it issues the &#8220;dir&#8221; command and puts the output in a file on your local server. The script then closes the ftp session and checks the contents of the local file for anything that it should be picked up from the remote server.  The script then calls ftp a second time to do the actual transfer.  For each file transferred, you can then check the size of the local file to the information about the file that was obtained on the first ftp call.  If they are not the same, then the file was not transferred successfully.<br />
For example:<br />
#set a variable with the wildcard of files you are looking for<br />
FILEWC=&#8221;S*&#8221;<br />
These two variables hold the value for the file name where I hold information from the ftp sessions<br />
RFINFO=&#8221;$LDIR/remote_directory_info.dif&#8221;<br />
RFINFO2=&#8221;$LDIR/remote_directory_info2.dif&#8221;<br />
FTPLOG=&#8221;$LDIR/ftplog.log&#8221;<br />
FTPHISTORY=&#8221;$LDIR/ftp_history.log&#8221;<br />
# other variables are also used to store the name/address of the ftp server and the connection #information.  This makes it easy to modify the script to handle multiple ftp requirements:</p>
<p>ftp -nciv &gt; $FTPLOG 2&gt;&amp;1  &lt;&lt;EOT<br />
  open $FTPSERVER<br />
  user $RUSER $RPWD<br />
  cd $RDIR<br />
  dir $FILEWC $RFINFO<br />
EOT<br />
FTPSTATUS=$?<br />
if [ $FTPSTATUS -ne 0 ] ; then<br />
    return $FTPSTATUS<br />
fi<br />
NumToTransfer=`cat $RFINFO | /usr/bin/wc -l `<br />
if [ $NumToTransfer -eq 0 ]; then<br />
   echo &#8220;$CURDATE &#8211; No files to transfer&#8221; &gt;&gt;$FTPHISTORY<br />
else<br />
   echo &#8220;$CURDATE &#8211; Files to transfer: $NumToTransfer&#8221; &gt;&gt;$FTPHISTORY<br />
   FLIST=`cat $RFINFO | awk -f $LDIR/awkname.dat`<br />
fi</p>
<p>#in this code snippet, it builds a list of files to retrieve into a variable named FLIST</p>
<p>There is then another piece of our script that actually makes the second connection, for each file to be transferred, and retrieves the files. The variabel ftpmode is used to pass the command to set the transfer mode of either BIN or ASC.</p>
<p>for eachfile in $FLIST;<br />
do<br />
   ftp -nicv &gt;$FTPLOG 2&gt;&amp;1 &lt;&lt;EOT<br />
     open $FTPSERVER<br />
     user $RUSER $RPWD<br />
     cd $RDIR<br />
     $FTPMode<br />
     dir $eachfile $RFINFO2<br />
     get $eachfile<br />
      quit<br />
EOT<br />
   FTPSTATUS=$?<br />
   if [ $FTPSTATUS -ne 0 ] ; then<br />
      return $FTPSTATUS<br />
   fi<br />
# Check the file size that was actually transfered<br />
   FSIZE=`/usr/bin/ls -l $eachfile | /usr/bin/awk &#8216;{print $5}&#8217;`<br />
   RFSIZE=`cat $RFINFO |grep $eachfile   | awk  -f $LDIR/awksize.dat`<br />
   RFSIZE2=`cat $RFINFO2 |grep $eachfile | awk  -f $LDIR/awksize.dat`<br />
   if [ $FSIZE -ne $RFSIZE2 ] ; then<br />
     echo &#8220;$CURDATE &#8211; FILE $eachfile SIZE NOT EQUAL &#8211; $FSIZE &#8211; $RFSIZE2&#8243; &gt;&gt;$FTPHISTORY<br />
     echo &#8220;File size not equal!!  Local: $FSIZE,  Remote: $RFSIZE2&#8243; &gt;&gt; $FTPLOG<br />
     FTPINCOMPLETE=1<br />
     return<br />
   fi<br />
   echo &#8220;$CURDATE &#8211; File $eachfile received &#8211; Size: $FSIZE&#8221; &gt;&gt;$FTPHISTORY<br />
   let NumTransferred=$NumTransferred+1<br />
   if [ $NumTransferred -ge $FTPLIMIT ] &amp;&amp; [ $FTPLIMIT -ne 0 ] ; then<br />
      break<br />
   fi</p>
<p>I may have missed documenting some of the variables here, but I hope this helps.<br />
Regards,</p>
<p>Larry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gilly400</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/script-to-extract-files-information-from-ftp-server/#comment-56604</link>
		<dc:creator>gilly400</dc:creator>
		<pubDate>Tue, 23 Sep 2008 14:38:37 +0000</pubDate>
		<guid isPermaLink="false">#comment-56604</guid>
		<description><![CDATA[Hi,

I don&#039;t know if your FTP server has this functionality, but on the AS400 you can use a &quot;dir (DISK&quot; command for example :-

dir abc* (DISK

which will create a file with a list of the directory contents, which you can then retrieve using an FTP get command.

Regards,

Martin Gilbert.]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I don&#8217;t know if your FTP server has this functionality, but on the AS400 you can use a &#8220;dir (DISK&#8221; command for example :-</p>
<p>dir abc* (DISK</p>
<p>which will create a file with a list of the directory contents, which you can then retrieve using an FTP get command.</p>
<p>Regards,</p>
<p>Martin Gilbert.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 6/9 queries in 0.011 seconds using memcached
Object Caching 296/299 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-19 23:55:11 -->