Skip to content

Conect to Network System in C#.net

satish Dandibotla

Asked Feb 7, 2008, 12:49 AM EST1 answer
Share
LinkedInX
Hi friends
I want had a question that how to connect to network system in C#.net ,
I had IP address,UserID and Password and i had to check whether there is a  file in the Network Sytem
Thanks
Satish

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
            try
                {
                    string uri = "ftp://"  + ftpaddress + "/" + fileInf.Name;
                    FtpWebRequest reqFTP;
                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
                    reqFTP.Credentials = new NetworkCredential(username, password);
                    reqFTP.KeepAlive = false;
                    reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;
                    FtpWebResponse fb = (FtpWebResponse)reqFTP.GetResponse();
                    long cnlen = fb.ContentLength;
                    if (cnlen > 0)
                        MessageBox.Show("File is found");
                }
                catch(WebException ex)
                {
                    // if(fw.StatusCode == FtpStatusCode.FileActionAborted)                             
                    //if(es.Status == FtpStatusCode.ActionNotTakenFileUnavailable)
                    FtpWebResponse fw = (FtpWebResponse)ex.Response;
                    if (fw.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
                        MessageBox.Show("File Not Found");
                }           
            }
    0