trunk/src/LythumOSL.Core/Net/SimpleFtp.cs
/// <summary>
/// File download. 
/// 
/// You may specify SimpleFtp::RemoteDirectory 
/// if you wish to change directories while working with this class object instance
/// if you don't want to recreate object
/// </summary>
/// <param name="localFile"></param>
/// <param name="remoteFile"></param>
/// <returns></returns>
File download.

You may specify SimpleFtp::RemoteDirectory
if you wish to change directories while working with this class object instance
if you don't want to recreate object
File download . You may specify SimpleFtp :: RemoteDirectory if you wish to change directories while working with this class object instance if you don ' t want to recreate object
public void Download (string localFile, string remoteFile)
		{
			FtpWebRequest request = null;
			FtpWebResponse response = null;
			FileStream localStream = null;
			Stream responseStream = null;
			try
			{
				Error();
				request = InitRequest(
					Url + RemoteDirectory + remoteFile);
	            request.Method = 
	            	WebRequestMethods.Ftp.DownloadFile;
	            response = 
	            	(FtpWebResponse)request.GetResponse();
	            responseStream = response.GetResponseStream();
	            localStream = new FileStream(
	            	localFile, FileMode.Create);
	            byte[] buffer = new byte[BufferSize];
	            int bytesRead = responseStream.Read(buffer, 0, BufferSize);
	            try
	            {
	                while (bytesRead > 0)
	                {
	                    localStream.Write(buffer, 0, bytesRead);
	                    bytesRead = responseStream.Read(buffer, 0, BufferSize);
	                }
	            }
	            catch (Exception ex) 
	            {
	            	Error(ex);
	            }
	            finally
	            {
		            localStream.Close();
		            responseStream.Close();
		            response.Close();
		            request = null;
	            }
	        }
	        catch (Exception ex) 
	        { 
	        	Error(ex);
	        }
		}
public void Download ( string localFile , string remoteFile ) { FtpWebRequest request = null ; FtpWebResponse response = null ; FileStream localStream = null ; Stream responseStream = null ; try { Error ( ) ; request = InitRequest ( Url + RemoteDirectory + remoteFile ) ; request . Method = WebRequestMethods . Ftp . DownloadFile ; response = ( FtpWebResponse ) request . GetResponse ( ) ; responseStream = response . GetResponseStream ( ) ; localStream = new FileStream ( localFile , FileMode . Create ) ; byte [ ] buffer = new byte [ BufferSize ] ; int bytesRead = responseStream . Read ( buffer , 0 , BufferSize ) ; try { while ( bytesRead > 0 ) { localStream . Write ( buffer , 0 , bytesRead ) ; bytesRead = responseStream . Read ( buffer , 0 , BufferSize ) ; } } catch ( Exception ex ) { Error ( ex ) ; } finally { localStream . Close ( ) ; responseStream . Close ( ) ; response . Close ( ) ; request = null ; } } catch ( Exception ex ) { Error ( ex ) ; } }
File download.
File download .
// Reset error status // Request // Method // Init response communication // Get response stream // Open a file stream to write local file // Data buffer // Download the file writing buffered data
None
localFile
string
None
remoteFile
string
None