如何使用FTP检查目录是否存在?
问题描述:
帮我使用FTP检查目录
Help me to check the directory using FTP
using BytesRoad.Net.Ftp;
FtpClient ftpClient = new FtpClient();
// use passive mode
ftpClient.PassiveMode = true;
int timeout = 0;
// connect to the specified FTP server
ftpClient.Connect(timeout,"URL ", 11 );
ftpClient.Login(timeout,USERNAME,PASSWORD);
rootDirectory = ftpClient.GetWorkingDirectory(timeout);
target = rootDirectory + "/testfolder " ;
我需要检查"target(testfolder)"是否存在
保存测试文档文件之前.
没有像directoryexists这样的扩展名.
I need to check the "target(testfolder)" is exists or not
before saving the test document file.
There is no extensions like directoryexists.
string file_to_save = target + "/test.doc";
// synchronously upload the file
ftpClient.PutFile(0, file_to_save , @"C:\test.doc" );
ftpClient.Disconnect(timeout);
谢谢
SwaxRak
Thanks
SwaxRak
答
如果标准System.Net.FtpWebRequest
可以完美地完成工作,为什么还要使用第三方BytesRoad
?
如果仍要使用BytesRoad
,请询问该库的作者.
我建议您使用标准的System.Net
,它是……很好,标准,有据可查,经过测试,可以完美地完成工作.在此处查看您的问题(非常简单)的可能答案之一:
http://stackoverflow.com/questions/2769137/c- how-to-check-if-an-ftp-directory是否存在 [
Why would you use third-partyBytesRoad
if standardSystem.Net.FtpWebRequest
would do the job perfectly?
If you still want to useBytesRoad
, ask the author(s) of this library.
I recommend you use standardSystem.Net
which is… well, standard, well documented, tested and perfectly do the job. See one of the possible answers to your (very simple) Question here:
http://stackoverflow.com/questions/2769137/c-how-to-check-if-an-ftp-directory-exists[^].—SA