c# ftp library
场景:关于 C# FTP Library奇怪的有关问题
关于 C# FTP Library奇怪的问题
我需要做一个ftp的上传 采用http://ftplib.codeplex.com/
if (!sftp.DirectoryExists("/" + dirname)) 判断是否存在该文件夹 如果不存在则创建
第一次没有文件夹,则创建了,但是第二次还是判断没有该文件夹
断点调试后sftp.DirectoryExists("/" + dirname) 一直是false
------解决方案--------------------
根据下面链接中的讨论,判断文件夹是否存在可能有BUG,讨论最后有个解决方法,你看看是否可以解决你的问题
DirectoryExists method always False
关于 C# FTP Library奇怪的问题
我需要做一个ftp的上传 采用http://ftplib.codeplex.com/
public FtpConnection sftp = new FtpConnection("192.168.12.56", 22, "administrator", "1");
private void SendFile(string dirname, string filename)
{
sftp.Open();
sftp.Login();
if (!sftp.DirectoryExists("/" + dirname))
{
sftp.CreateDirectory("/" + dirname);
}
sftp.PutFile(localurl + "/" + filename, "/" + dirname + "/" + filename);
sftp.Close();
}
if (!sftp.DirectoryExists("/" + dirname)) 判断是否存在该文件夹 如果不存在则创建
第一次没有文件夹,则创建了,但是第二次还是判断没有该文件夹
断点调试后sftp.DirectoryExists("/" + dirname) 一直是false
------解决方案--------------------
根据下面链接中的讨论,判断文件夹是否存在可能有BUG,讨论最后有个解决方法,你看看是否可以解决你的问题
DirectoryExists method always False
using (FtpConnection ftp = new FtpConnection(ftpHost, username, password))
{
ftp.Open(); /* Open the FTP connection */
ftp.Login(); /* Login using previously provided credentials */
/* Get parent directory of the given path */
String parrentDirectory = String.Format("/{0}",Path.GetDirectoryName(directory).Replace(Path.DirectorySeparatorChar,'/'));
/* Get name of the directory */
String checkingDirectory = String.Format("{0}", Path.GetFileName(directory)).ToLower();
/* Get all child directories info of the parent directory */
var ftpDirectories = ftp.GetDirectories(parrentDirectory);
/* check if the given directory exists in the returned result */
result = ftpDirectories.Any(d => d.Name.ToLower() == checkingDirectory);
}