我正在寻找一个代码来从FTP中删除图像,但确实无法正常工作 我尝试使用此代码但不适合我:
Dim FTPRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://myftpname.es/Html/images/" & imagename), System.Net.FtpWebRequest)
FTPRequest.Credentials = New System.Net.NetworkCredential("FTPUsername", "FTPPassword")
FTPRequest.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
FTPRequest.UsePassive = True
FTPRequest.UseBinary = True
FTPRequest.KeepAlive = False
如何从ftp中删除图像? 感谢
答案 0 :(得分:2)
此代码不会从ftp中删除图像
那是因为你从未真正执行它,你只是初始化它。要发出WebRequest
,您需要获得回复:
var response = FTPRequest.GetResponse()
答案 1 :(得分:0)
您是否尝试过使用FtpClient类?
Dim client as new System.Net.FtpClient.FtpClient()
client.Credentials = new NetworkCredential("FTPUsername", "FTPPassword")
client.Host = "ftp://myftpname.es"
client.Connect()
client.DeleteFile("Html/images/" & imageName)