Directory operations on ftp in c#
public static bool FtpDirectoryExists(string directoryPath, string ftpUser, string ftpPassword)
{
bool IsExists = true;
try
{ FtpWebRequest request = (FtpWebRequest)WebRequest.Create(directoryPath); request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
request.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
}
catch (WebException ex)
{ IsExists = false;
} return IsExists;
}
public static void CreateDirectory(string directoryPath, string ftpUser, string ftpPassword)
{
try
{WebRequest request = WebRequest.Create(directoryPath);
request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
using (var resp = (FtpWebResponse)request.GetResponse())
{ Console.WriteLine(resp.StatusCode); }
}
catch (Exception ex)
{ Console.WriteLine(ex.Message); }
}
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home