|
-
Dec 9th, 2013, 11:47 AM
#1
Thread Starter
New Member
[RESOLVED] Deleting a file from an FTP site (am I doing it correctly)
Hi,
I currently have the following portion of code below, which deletes a file
"solarradiationchart.png" from an FTP site, from within my program.
But a couple of users are having problems with my program which I think I have
pinpointed to this portion of code, as the other code that runs after
it does not get processed.
Therefore I have two questions below, which I hope someone can answer.
1.
Is there additional code that I will need to add to handle if the file does not exist
on the FTP server? or is the code OK as it is?
2.
Also should I be using "response.Dispose()" or something similar to fully close and exit out cleanly?
I did try "response.Dispose()" but VB would not allow it.
As I am still very much learning on how to working with FTP sites from within VB.NET, therefore
if it is possible could someone show me what code I should add and where, it would be much appreciated.
Code:
If CheckBox2.Checked = False Then
'Delete "solarradiationchart.png" on FTP server if it exists
Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://" + FTP_URL + "solarradiationchart.png"), System.Net.FtpWebRequest)
request.Credentials = New System.Net.NetworkCredential(FTP_UserName, FTP_Password) '// put username and password in here.
request.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
Dim response As FtpWebResponse = request.GetResponse
Console.WriteLine("Delete status: {0}", response.StatusDescription)
response.Close()
End If
FYI.
I am also going to add a "Try and Catch" to the code to see if I can find out
what the error is which will also hopefully help.
-
Dec 9th, 2013, 12:21 PM
#2
Re: Deleting a file from an FTP site (am I doing it correctly)
Is there additional code that I will need to add to handle if the file does not exist
on the FTP server? or is the code OK as it is?
How about checking the file first if it exists then perform deletion if found?
http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx
or have a look at this implementation:
http://www.codeproject.com/Tips/1636...-an-FTP-server
Last edited by KGComputers; Dec 9th, 2013 at 12:32 PM.
-
Dec 10th, 2013, 05:54 AM
#3
Thread Starter
New Member
Re: Deleting a file from an FTP site (am I doing it correctly)
KGComputers,
Thanks for your advice and links 
I have now added the "File Checking Function" to my code and so far
all seems to be working correctly without the previous error.
All the best
Mark
-
Dec 10th, 2013, 05:59 AM
#4
Re: Deleting a file from an FTP site (am I doing it correctly)
Mark,
Welcome! Kindly mark this thread as resolved... 
Greg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|