且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查ftp服务器上是否存在指定的文件夹

更新时间:2023-08-21 20:33:28

这是非常混乱的。



http://www.example-code.com/csharp/ftp_dirExists.asp [ ^ ]



似乎使用了一个自定义组件,但你可以在那里看看他们是否这样做。你也可以尝试浏览目录,看看你得到了什么,或创建在任何情况下,如果它不会清空它。
This is pretty messy.

http://www.example-code.com/csharp/ftp_dirExists.asp[^]

seems to use a custom component, but you could look in there to see hwo they do it. You could also just try browsing to the directory, and see what you get back, or creating it in any case, if that doesn't empty it.


一种方法是:使用适当的列出目录System.Net.FtpWebRequest.Met hod 。该方法可以是 System.Net.WebRequestMethods.Ftp.ListDirectory System.Net.WebRequestMethods.Ftp。 ListDirectoryDe​​tail 。读取HTTP响应 System.Net.FtpWebResponse 中的数据,查看哪个目录存在,哪个目录不存在。



请参阅:

http://msdn.microsoft .com / zh-cn / library / system.net.ftpwebrequest.method.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.net .ftpwebresponse.aspx [ ^ ]。



-SA
One way is: list directories using appropriate System.Net.FtpWebRequest.Method. The method can be System.Net.WebRequestMethods.Ftp.ListDirectory or System.Net.WebRequestMethods.Ftp.ListDirectoryDetail. Read the data in HTTP response System.Net.FtpWebResponse to see which directory exists and which is not.

Please see:
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.method.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.ftpwebresponse.aspx[^].

—SA


大家好,



我通过使用
Hi All,

I've solved this problem by using
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;



实际上我通过使用上面的webrequest方法从FTP服务器获取所有文件和文件夹并将它们添加到列表框中,然后使用 foreach 如果存在则逐个循环检查。



希望你理解。


Actually I am getting all the files and folders from FTP server by using above webrequest method and add them into list box and after that by using foreach loop check one by one if it exist or not.

Hope you understand.