/**//* FTPFactory.cs Better view with tab space=4 Written by Jaimon Mathew (jaimonmathew@rediffmail.com) Rolander,Dan (Dan.Rolander@marriott.com) has modified the download method to cope with file name with path information. He also provided the XML comments so that the library provides Intellisense descriptions. use the following line to compile csc /target:library /out:FTPLib.dll /r:System.DLL FTPFactory.cs */ using System; using System.Net; using System.IO; using System.Text; using System.Net.Sockets; namespace WindowsApplication1 ...{
publicclass FTPFactory ...{
privatestring remoteHost,remotePath,remoteUser,remotePass,mes; privateint remotePort,bytes; private Socket clientSocket; privateint retValue; private Boolean debug; private Boolean logined; privatestring reply; privatestaticint BLOCK_SIZE =512; Byte[] buffer =new Byte[BLOCK_SIZE]; Encoding ASCII = Encoding.ASCII; public FTPFactory() ...{
remoteHost ="localhost"; remotePath ="."; remoteUser ="anonymous"; remotePass ="jaimon@school2000.co.uk"; remotePort =21; debug =false; logined =false; } /**//// /// Set the name of the FTP server to connect to. /// /// Server name publicvoid setRemoteHost(string remoteHost) ...{
this.remoteHost = remoteHost; } /**//// /// Return the name of the current FTP server. /// /// Server name publicstring getRemoteHost() ...{
return remoteHost; } /**//// /// Set the port number to use for FTP. /// /// Port number publicvoid setRemotePort(int remotePort) ...{
this.remotePort = remotePort; } /**//// /// Return the current port number. /// /// Current port number publicint getRemotePort() ...{
return remotePort; } /**//// /// Set the remote directory path. /// /// The remote directory path publicvoid setRemotePath(string remotePath) ...{
this.remotePath = remotePath; } /**//// /// Return the current remote directory path. /// /// The current remote directory path. publicstring getRemotePath() ...{
return remotePath; } /**//// /// Set the user name to use for logging into the remote server. /// /// Username publicvoid setRemoteUser(string remoteUser) ...{
this.remoteUser = remoteUser; } /**//// /// Set the password to user for logging into the remote server. /// /// Password publicvoid setRemotePass(string remotePass) ...{
this.remotePass = remotePass; } /**//// /// Return a string array containing the remote directory's file list. /// /// /// publicstring[] getFileList(string mask) ...{
if(!logined) ...{
login(); } Socket cSocket = createDataSocket(); sendCommand("NLST "+ mask); if(!(retValue ==150|| retValue ==125)) ...{
thrownew IOException(reply.Substring(4)); } mes =""; while(true) ...{
int bytes = cSocket.Receive(buffer, buffer.Length, 0); mes += ASCII.GetString(buffer, 0, bytes); if(bytes < buffer.Length) ...{
break; } } char[] seperator =...{
''};